Answer the question
In order to leave comments, you need to log in
How to implement search for multiple values in one field?
Hello everyone, please help me solve my problem. Let us have blogs. Blogs are associated with M:M tags. Accordingly, there is a table that lists all these tags (tags). How to display blogs, with a certain tag, this is clear to me, but how can I select all blogs in the SearchModel that have absolutely all available tags?
I have tried 2 options. Others do not climb into the head, it was not possible to google.
Option 1:
$tags = ArrayHelper::getColumn(Tag::find()->all(),'id'); // тут я получаю массив со всеми существующими тэгами
$query->andFilterWhere([
'service_id' => $tags
]);
$tags = ArrayHelper::getColumn(Tag::find()->all(),'id'); // тут я получаю массив со всеми существующими тэгами
foreach ($tags as $one) {
$query->andFilterWhere([
'service_id' => $one
]);
}
Answer the question
In order to leave comments, you need to log in
not very deeply penetrated, but firstly:
apparently, strict equality is needed because $this->service == 0)
it is null as well.
Then you wrote some heresy, as I understand it, you need something like this:
if ($this->service !== 0){
$query->andFilterWhere([ 'service_id' => $this->service]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question