I have a many to many bidirectional relation in my app, right like in official guide.
Using a relational model User
<-> Group
from the link above - lets say I want to select all entries from Group
entity with the following condition
1) Select all groups that have at least one user related to a group.
2) Select all groups that have no users in it.
I can't figure out how to prepare a correct DQL, any ideas please.
答案 0 :(得分:0)
在纯DQL中,您可以编写为
SELECT g,
COUNT(u.id) AS total_users
FROM Entity\Group g
LEFT JOIN g.users u
GROUP BY g.id
HAVING total_users >= 0