A
A
Alexandr Yatskanych2016-02-25 17:03:09
Yii
Alexandr Yatskanych, 2016-02-25 17:03:09

How to write correct AND (LIKE OR LIKE) query using Query Builder?

I need to write this type of
$query->where(.....);
$query->and(.....)
$query->andFilterWhere(['like','user.first_name',$this->query,['or like','user.middle_name'=>$this ->query],['or like','user.last_name'=>$this->query]]);
The problem is that it only searches for the first field "first_name".
Generated query without OR operator at all

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2016-02-26
@yatskanychSaniok

$query->andFilterWhere([
    'or',
    ['like', 'user.first_name', 'fName'],
    ['like', 'user.middle_name', 'mName'],
    ['like', 'user.last_name', 'lName']
]);

D
Dmitry Voronkov, 2016-02-25
@DmitryVoronkov

$query->where(.....);
$query->and(.....)
$query->andWhere(...)
$query->orWhere(...);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question