我在一篇关于 Zend 的帖子中看到了一个答案的开头:将子查询与原则 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()