Jack
Jack

Reputation: 347

Yii2 Active record how create relation between mongo models

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

Upvotes: 2

Views: 1510

Answers (1)

Alex
Alex

Reputation: 8072

The same way as using relational databases:

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

Upvotes: 1

Related Questions