Answer the question
In order to leave comments, you need to log in
How to refine a query in Yii?
I have 2 tables:
USER
id, name, surname
UserUser
u_id1, u_id2, date, status
I have this action in the USER model:
public function getUsers($status)
{
return $this->hasMany(UserUser::className(), ['u_id1' => 'id'])
->where(['status' => $status]);
}
Answer the question
In order to leave comments, you need to log in
return $this->hasMany(User::className(), ['id' => 'u_id2'])->viaTable(UserUser::tableName(), ['u_id1' => 'id'],
function($ query) {
$query->where(['status' => 1]);
})->andWhere(['like', 'name', $input])
->orWhere(['like', 'surname' , $input]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question