I have user
and post
table with oneToMany
relation:
In Post Model:
public function getUser() {
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
And in User Model:
public function getPosts() {
return $this->hasMany(Post::className(), ['user_id' => 'id']);
}
I want find All users that has at least a active post. But I don`t have any idea.
My target SQL :
SELECT * FROM `user`
where id in (select user_id from post where status = 1)
What do I do?
User::find()->where(...
notice: its important that created with find(), because I want use it in search model
Thanks.