问题
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