A
A
alex_belouss2017-07-06 18:05:06
Yii
alex_belouss, 2017-07-06 18:05:06

How to make OR instead of AND in active record?

Query snippet: ->andWhere()
When there are several values ​​in the $_GET['season'] array, then the query is like this ((`season` LIKE '%Winter%' AND `season` LIKE '%Summer%' AND `season` LIKE '%Demi-season%' AND `season` LIKE '%Year-round%'))
I need to do instead of AND OR. How can you achieve?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-07-06
@slo_nik

Good evening.
Well, how else can you do it if you don't read the documentation ?
In Russian.

M
Maxim Timofeev, 2017-07-09
@webinar

exist ->andWhereand exist ->orWhere.
I also note that there is such a structure:
In your case, if I understand correctly, it should be like this:

$model = SomeModel::find();
foreach($search_words_array as $word){
  $model->orWhere(['like','season',$word]);
}
print_r($model->asArray()->all());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question