Closed waltercruz closed 9 years ago
I am interested too.
Sorry I didn't understand your question. What do you mean by tagged types ?
I think he means how to search entity by 2+ matching tags i.e. find all items with tag "foo" and "bar".
You can do something like this:
// $dqlAlias - alias of your root entity
// $taggableType - desired taggable type
// $qb - your query builder
// $data - list of tags
$qb->setParameter('tag_resource_type', $taggableType);
foreach ($data as $index => $tag) {
$tagsQb = $this->tagManager->getRepository()->createQueryBuilder('tag' . $index)
->join("tag{$index}.tagging", 'tagging' . $index)
->where("tagging{$index}.resourceType = :tag_resource_type")
;
$subQuery = $tagsQb
->andWhere($tagsQb->expr()->eq("tag{$index}.name", ':tag_name' . $index))
->select("tagging{$index}.resourceId")
->getDql()
;
$qb->andWhere($qb->expr()->in($dqlAlias . '.id', $subQuery));
/** @var \DoctrineExtensions\Taggable\Entity\Tag $tag */
$qb->setParameter('tag_name' . $index, $tag->getName());
}
Will not comment on performance here.
hth
Suppose that I have to search tagged types by 2 or 3 tags... How should I do?
And... the column resource_id should be integer don't?