2011-11-21 65 views
0

我如何能在教義2用做 - >從() - > leftjoin ...學說2左加入

像這樣

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.' 

回答

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();