2011-03-08 119 views
1

有沒有什麼辦法可以在使用symfony的Doctrine中運行這個sql查詢?在SYMFONY中使用DOCTRINE的LEFT JOIN語句中的SELECT語句?

$q = "SELECT a.id as app_id, b.title as gameTitle FROM application a 
    LEFT JOIN application_translation b on a.id=b.id 
    LEFT OUTER JOIN (SELECT m.application_id as m_id, count(m.member_id) as total 
    FROM member_application m GROUP BY m.application_id) x on x.m_id = a.id 
    WHERE a.is_active=1 AND a.is_mobile = 1 
    ORDER BY x.total DESC"; 

更新

感謝您的答覆。只有一兩件事,我怎麼能轉換

對象(sfOutputEscaperArrayDecorator)#524

對象(sfOutputEscaperIteratorDecorator)#560

使用您的代碼?我認爲這是因爲水合物模式,但我不明白。

回答

2

您可以嘗試執行你的原始SQL這樣的:

$q = "SELECT a.id as app_id, b.title as gameTitle FROM application a 
LEFT JOIN application_translation b on a.id=b.id 
LEFT OUTER JOIN (SELECT m.application_id as m_id, count(m.member_id) as total 
FROM member_application m GROUP BY m.application_id) x on x.m_id = a.id 
WHERE a.is_active=1 AND a.is_mobile = 1 
ORDER BY x.total DESC"; 
$doctrine = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh(); 
$result = $doctrine->query($q);