2011-03-08 89 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);