学说2离开加入

时间:2011-11-21 16:46:44

标签: doctrine doctrine-orm

我怎么能在Doctrine 2中使用 - > from(), - > leftjoin ...

类似这样的事情

select c.* from category left join domande as d on d.category_id = c.id left join age as a on d.age_id = a where a.age > 30 and a.id is not null

我一直在

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Semantical Error] line 0, col 63 near 'd ORDER BY c.ordine': Error: Identification Variable Entities\Domanda used in join path expression but was not defined before.'

1 个答案:

答案 0 :(得分:3)

您的查询中可能有拼写错误 - 请注意,您在问题中的两个地方的“Domande”和“Domanda”拼写不同。此外,您的SQL未提及ORDER BY子句,但错误消息确实如此。

以下是用DQL编写的查询,包括错误消息中引用的ORDER BY子句。

$query = $em->createQuery(
    'SELECT c FROM Entities\Category LEFT JOIN c.domande d LEFT JOIN d.age a 
     WHERE a.age > 30 AND a.id IS NOT NULL ORDER BY c.ordine');
$results = $query->getResult();