A
A
Alex Kheben2014-03-25 20:37:18
Yii
Alex Kheben, 2014-03-25 20:37:18

How to implement a model for a collection property?

ODM is used by the one in Yii2.
I have a collection in Mongodb

collection: [
    {
        _id: ObjectId(...)
        prop1: 'value',
        prop2: [
            { _id: ObjectId(...), prop1: 'value', prop2: 'value' },
            ...
        ]
    }
];

For this collection, it is necessary to implement a model that would allow validating the data not only of the main collection, but also of the elements of the collection property. Those. the array of objects in prop2 should behave like a model.
In general, it is ideal to make a model for collection.prop2.
I searched all over the Internet and did not find a solution, there is nothing even close. Maybe someone here has come across this problem and knows how to solve it. At least tell me where to dig. I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question