开发者

Doctrine2 - 3 tables relation - Select

开发者 https://www.devze.com 2023-03-21 23:07 出处:网络
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).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消