2016-06-09 68 views
1

我看到一个关于Zend的帖子中的答案的开始:Join subquery with doctrine 2 DBAL 不幸的是,我不能管理它的工作。我试图aimfeld soltuion这样的:加入与学说和Symfony 2子查询

$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的? 有什么想法? 感谢

+0

仔细查看。你能发现getSQL和getDQL的区别吗? – Cerad

回答

0

使用SQL代替DQL:

$subSelect->getSQL()