I have 2 entities, Picture and Tag, with ManyToMany relation. That means 3 tables: picture, tag and pictures_tags.
I want to select some pictures and join their tags in the same query. How can it be done in DQL?
I have 2 entities, Picture and Tag, with ManyToMany relation. That means 3 tables: picture, tag and pictures_tags.
I want to select some pictures and join their tags in the same query. How can it be done in DQL?
查询相当简单,都是关于fetch-joins 的:
$picture = $em->createQuery(
"SELECT p, t FROM Entity\Picture p JOIN p.tags t WHERE p.id = :pictureId"
)->getResult();
$query = $em->createQuery("Select * from pictures p
join pictures_tags pt on p.pictureid=pt.pictureid
join tag on tag.id=pt.tagid");
$users = $query->getResult();