Join subquery with doctrine 2 DBAL

前端 未结 3 1793
谎友^
谎友^ 2020-12-03 08:24

I\'m refactoring a Zend Framework 2 application to use doctrine 2.5 DBAL instead of Zend_DB (ZF1). I have the following Zend_Db query:

$subS         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 09:19

    Selected answer is over-complicated and the second one is wrong (it won't return anything is the condition is totally fullfilled, meaning if there is no row at all returned by the sub-query).

    But yes, you can refactor to use IN:

    $qb->leftJoin('user_survey_status_entries', 
                  'firstAccess',
                  Join::WITH, 
                  $qb->expr()->in($qb2->getDQL())
    );
    

    In your case, don't forget to move the us.userSurveyID = firstAccess.userSurveyID condition into $qb2.

提交回复
热议问题