Answer the question
In order to leave comments, you need to log in
Yii2 how to write a condition for a linked table?
Good afternoon.
I've been fighting for a day now.
We have a table model Video2user which stores user_id and video_id. There is also a Video table model in which there are id, code, party fields.
It is required to get the Code from the video base through Active Record where, for example, party = 2.
If on pure sql, then it looks like this
select v.code
from video2user v2u, video v
where v2u.video_id = v.id
and v.party = 2
and v2u.user_id = :user_id
order by v2u.video_id
public function getVideo(){
return $this->hasOne(Video::className(), ['id' => 'video_id'])->where(['party' => 2]);
}
$query2 = Video2user::find()->where(['user_id' => 5555])->with('video')->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question