This is probably an easy one but I can't figure it out nor find an answer.
I have a simple Article and ArticleTag Entities with many to many relationship. How can I get all articles with a certain tag (or tags)?
My following tries:
$qb = $repository->createQueryBuilder('a')
// ...
->andWhere('a.tags = :tag')
->setParameter('tag', 'mytag')
// ...
or
->andWhere(':tag in a.tags')
->setParameter('tag', 'mytag')
...didn't work. Thanks!
And the winner is ... drumroll, please ...
$qb = $repository->createQueryBuilder('a')
// ...
->andWhere(':tag MEMBER OF a.tags');
->setParameter('tag', $tag);
// ...
Thanks to everyone who has taken the time to read and think about my question!
I think you can adаpt this example (from documentation):
$query = $em->createQuery('SELECT u.id FROM CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM CmsPhonenumber p WHERE p.user = u.id)');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With