使用doctrine和Symfony 2加入子查询

时间:2016-06-09 15:34:57

标签: php mysql symfony doctrine-orm

我在一篇关于Zend的帖子中看到了答案的开头:Join subquery with doctrine 2 DBAL 不幸的是,我无法管理它。我尝试过这样的目标:

$qbaudio = $em->createQueryBuilder();
    $subSelect = $qbaudio->select ('a.id_support id_support','sum(a.duration) dureeTotale','count(a) nbAudio')
        ->from('MyBundle:AudioObject','a')
        ->groupBy('a.id_support')
        ->where('a.type = :audio_type')
        ->getQuery();
    $qb = $em->createQueryBuilder();
    $qb->select('sp.ref1','sp.title1','count(i) nbImage','sp.nbSupportSaisi','sum(a.duration) dureeTotale','count(a) nbAudio','a.sampling')
      ->from('MyBundle:Storage', 'st')
            ->leftJoin('p.sides','si')
            ->leftJoin('si.support','sp')
            ->leftJoin('sp.images','i')
            ->leftJoin('sp.audioObjects', sprintf('(%s)',$subSelect->getDQL()), 'a', 'ON sp.id = a.id_support')
            ->groupBy('sp.id')
            ->setParameter('audio_type', 'MP3')

不幸的是我收到了这条消息:

Error: Expected end of string, got 'SELECT'

如果可以使用ZEnd,为什么不使用Symfony? 任何的想法? 感谢

1 个答案:

答案 0 :(得分:0)

使用SQL而不是DQL:

$subSelect->getSQL()
相关问题