Doctrine2 - 3 tables relation - Select
I have a relation that looks like this:
Category <=== Host <===> User
Basically User-Host is a many-to-many relation, and each Host have one Category (one-to-many).
Somehow I need to list what Categories a User has hosts in. Something like:
Select Categories From Categories Where Host Has User == MyUser.
So far I can only list 开发者_如何学Pythonwhat Hosts a User has, and what Category a Host has. With plain SQL I need 2 Joins, but cant find out a way to do it with Doctrine 2. I have been playin all day with QueryBuilder but am not even close yet.
Any tips on this?
DQL:
SELECT c
FROM Entity\User u
INNER JOIN u.hosts h
INNER JOIN h.category c
WHERE u.id = :user
That should do the trick.
精彩评论