Answer the question
In order to leave comments, you need to log in
How to use JOIN in Yii2?
Hello! I'm using JOIN for the first time, so I'll do something wrong... help me solve the problem...
so I wrote this query
Category::find()->leftJoin('post', 'post.category_id = category.id')->all()
Answer the question
In order to leave comments, you need to log in
Category::find()->joinWith('post')->all()
and add a getPost relationship to the Category model
public function getPost(){
return $this->hasMany(Post::classname(),['category_id' => 'id']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question