0
我使用Symfony2
和FOSCommentBundle
,並且我已將comment
添加到特定實體App\MyBundle\Post
。Symfony2 + Doctrine:從2個實體中檢索信息
我想要檢索有關的所有App\MyBundle\Post
,並且所有指定comment
的所有信息,我的意思是,如果我有一個職位2條評論,我想它返回我到我行,例如:
P.*, 2 as nbComment
所以我也試試這個代碼:
$query = $this->getEntityManager()->createQuery ('
SELECT P, COUNT(C.id) as nbComment
FROM AppMyBundle:Post P
LEFT JOIN AppMyBundle:Comment C ON C.id=CONCAT('post_',P.id)
GROUP BY P.id
ORDER BY P.dEvent DESC, P.dCreated DESC'
);
但我有一個錯誤:
[Semantical Error] line 0, col 96 near 'Com ON C.id=CONCAT("post_",P.id) WHERE': Error: Identification Variable Comment used in join path expression but was not defined before.
請幫我
感謝薩姆
好吧,我知道我不能按照文檔左連接'on',但是我沒有在郵件實體和評論實體之間的「物理」鏈接。我擁有的唯一鏈接是:comment.id = CONCAT('post _',post.id) – Sam 2012-01-17 09:12:26
哦。我懂了。我認爲你真的應該有一個物理鏈接。寫一個sql遷移到一個新的表結構,你將獲得速度的可用性。 – greg0ire 2012-01-17 09:19:16
你是什麼意思?我必須像CONCAT('mytable _',mytable.id)那樣有comment_id,因爲我想實例化幾個實體的註釋。所以我不知道我該怎麼做... – Sam 2012-01-17 09:41:05