I am trying to add to two different search variations to my project. There is a model "User" and a model "Tag". A User has many Tags. Now I want to be able to search the Users with specific Tags. Either I want to show all Users that has any of the specified tags. I got this working this way:
$query = $this->Users->find();
$query->matching('Tags', function ($q) {
return $q->where(['Tags.name' => 'Tag1'])
->orWhere(['Tags.name' => 'Tag2']);
});
But now I want to find all Users that have both Tags at the same time.
I tried ->andWhere
instead of ->orWhere
, but the result is always empty.
How can I find Users that contain multiple Tags?
Thanks