Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question