具有多个连接表的 Doctrine DQL

Dud*_*ude 5 doctrine dql symfony

我有实体 **target,citytarget,city,cityplace,place

citytarget 和 cityplace 是连接 t&c 和 c&p 的数据透视表

我需要给定城市名称和目标 ID 的地点

我尝试了以下 DQL:

SELECT t,c,p FROM MulticatorBundle:Target t
            join t.cities ct
            join ct.cities c
            join c.places cp
            join cp.places p
            where c.name like '%Stahmeln%'
Run Code Online (Sandbox Code Playgroud)

但我收到:

结果:未找到别名为“c”的实体结果的父对象。父别名是“ct”。

我不知道更多......

一个简单的 SQL 可以是:

select * from target 
left join citytarget on citytarget.target_id = target.id
left join city on citytarget.city_id = city.id 
left join cityplace on cityplace.city_id = city.id 
left join place on cityplace.id = place.id 
where target.id = 1 
and city.name like \'%Stahmeln%\'
Run Code Online (Sandbox Code Playgroud)

阿德里安

小智 10

您始终需要选择父实体。在这种情况下:

SELECT ct, c, cp, t, p
Run Code Online (Sandbox Code Playgroud)

需要


abd*_*iel 3

你需要做

SELECT t,ct, c, cp ,p FROM MulticatorBundle:Target t
            join t.cities ct
            join ct.cities c
            join c.places cp
            join cp.places p
            where c.name like '%Stahmeln%'
Run Code Online (Sandbox Code Playgroud)

希望这对您有帮助