Yii2 Active record how create relation between mongo models

…衆ロ難τιáo~ 提交于 2020-01-15 04:58:06

问题


I have 2 classes which extends\yii\mongodb\ActiveRecord for example Users and Posts relations between this classes User have many posts.


回答1:


The same way as using relational databases:

public function getPosts()
{
    return $this->hasMany(Posts::className(),['_id'=>'user_id']);
}


来源:https://stackoverflow.com/questions/29347016/yii2-active-record-how-create-relation-between-mongo-models

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!