【问题标题】:Join subquery with doctrine and Symfony 2使用教义和 Symfony 2 加入子查询
【发布时间】:2016-06-09 15:34:56
【问题描述】:

我在一篇关于 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? 任何想法? 谢谢

【问题讨论】:

  • 仔细看。你能看出 getSQL 和 getDQL 的区别吗?

标签: php mysql symfony doctrine-orm


【解决方案1】:

使用 SQL 代替 DQL:

$subSelect->getSQL()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2015-02-18
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多