Nel controller che riceve i tags da cercare:
$tags = $values['tags'];
$query->select($this->Articles);
$query->select($this->Articles->Topics);
$query->select($this->Articles->Categories);
$query->select(['tot' => $query->func()->count('*')]);
$query->matching('Tags',function ($q) use ($tags) {
return $q->where(['Tags.id IN' => $tags]);
});
$query->group('Cards.id')->having(['tot' => count($tags)]);