我在一篇关于 Zend 的帖子中看到了答案的开头:Join subquery with doctrine 2 DBAL 不幸的是我无法让它工作。我试过这样的 aimfeld 解决方案:
$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 不行? 任何想法? 谢谢
最佳答案
使用 SQL 而不是 DQL:
$subSelect->getSQL()
关于php - 使用 doctrine 和 Symfony 2 加入子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37730391/