doushijia5684 2017-05-01 13: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-01 22:11
    关注

    You should modify your query to:

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

报告相同问题?

悬赏问题

  • ¥15 MATLAB解决问题
  • ¥20 哪位专业人士知道这是什么原件吗?哪里可以买到?
  • ¥15 关于#c##的问题:treenode反序列化后获取不到上一节点和下一节点,Fullpath和Handle报错
  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目