How to search multiple values in one field?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
9 views
Hi all, please help me to solve my problem. So let we have blogs. Blogs associated with tags M:M. Accordingly, there is a table which lists all these tags (tags). How to show the blogs with a specific tag it is clear to me, but how in the SearchModel to select all blogs that have absolutely all the available tags?
I tried out 2 options. Others never climb, googling failed.

Option 1:
$tags = ArrayHelper::getColumn(Tag::find()->all(),'id'); // here I get an array with all the existing tags $query->andFilterWhere([ 'service_id' => $tags ]);


Does not work, because it removes all the blogs that have at least some of the tags.

The course 2:
$tags = ArrayHelper::getColumn(Tag::find()->all(),'id'); // here I get an array with all the existing tags foreach ($tags as $one) { $query->andFilterWhere([ 'service_id' => $one ]); }


just not running)

Other options I do not have, please take a look.
by | 9 views

1 Answer

0 like 0 dislike
not much deeply delved into, but first:
probably need strict equality because $this->service == 0) this null including.
Then some kind of heresy You wrote, I understand you need something like this:
if ($this->service !== 0){ $query->andFilterWhere([ 'service_id' => $this->service]); }
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
35,430 users