Answer the question
In order to leave comments, you need to log in
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
Good evening.
Well, how else can you do it if you don't read the documentation ?
In Russian.
exist ->andWhere
and 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 questionAsk a Question
731 491 924 answers to any question