doushijia5684 2017-05-01 21:21
浏览 48
已采纳

DQL子查询问题

I'm trying to SLECT * FROM a table o where the vendor is what I pass.(this is in the context of a Doctrine Repository). I then want to run a subquery and SELECT * FROM AppBundle:PriceOption where p.offer is o. I'm getting a QueryException when running this code though:

public function getVendorFeaturedDeals(Vendor $vendor){
    $purchaseOptions = $this->
        getEntityManager()
        ->createQueryBuilder()
        ->from('AppBundle:PriceOption', 'p')
            ->innerJoin('p.offer', 'o')
        ->getDQL();


    $query = $this->createQueryBuilder('o');
    return $query
        ->where('o.vendor = :vendor')
        ->addSelect(sprintf('(%s)', $purchaseOptions))
        ->setParameter(':vendor', $vendor)
        ->getQuery()
        ->execute();
}

Here's the error : AppBundle\Tests\Service\VendorServiceTest::testGetVendorFeaturedDeals Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 18: Error: Unexpected 'FROM' Caused by Doctrine\ORM\Query\QueryException: SELECT o, (SELECT FROM AppBundle:PriceOption p INNER JOIN p.offer o) FROM AppBundle\Entity\Offer o WHERE o.vendor = :vendor

Any help would be appreciated, thanks!

  • 写回答

1条回答 默认 最新

  • dongqishou7471 2017-05-02 06:11
    关注

    You should modify your query to:

    $purchaseOptions = $this->
        getEntityManager()
        ->createQueryBuilder()
        ->select(['p', 'o'])
        ->from('AppBundle:PriceOption', 'p')
            ->innerJoin('p.offer', 'o')
        ->getDQL();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题