D
D
Dimon2015-05-21 18:38:34
Yii
Dimon, 2015-05-21 18:38:34

Who faced the problem, Yii2 mongoDB does not pull up dependent tables hasOne, hasMany?

Has anyone experienced connecting dependent tables (MongoDB base) in Yii2?

$this->hasMany(User::className(), ['role_id' => '_id'])
in this form does not work. (with hasOne() is the same).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimon, 2015-05-21
@Glimor

Maybe someone will come in handy. In order for tables to be connected through links, the data in the fields in both tables must be of the same type. (int or ObjectId). Therefore, when writing data to a table, you must manually set the data type, for example $model->role_id = new \MongoId("$model->role_id");, '_id' - must also be ObjectId or $model->role_id = (int) $model->role_id;, '_id' - must be int.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question