gpt4 book ai didi

php - DQL 子查询问题

转载 作者:行者123 更新时间:2023-11-29 10:51:03 26 4
gpt4 key购买 nike

我正在尝试从表 o 中 SLECT * ,其中供应商是我传递的内容。(这是在 Doctrine 存储库的上下文中)。然后我想运行一个子查询和 SELECT * FROM AppBundle:PriceOption ,其中 p.offer 是 o 。不过,我在运行此代码时遇到了 QueryException:

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();
}

这是错误:AppBundle\Tests\Service\VendorServiceTest::testGetVendorFeaturedDeals
Doctrine\ORM\Query\QueryException:[语法错误]第 0 行,第 18 列:错误:意外的“FROM”
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

如有任何帮助,我们将不胜感激,谢谢!

最佳答案

您应该将查询修改为:

$purchaseOptions = $this->
getEntityManager()
->createQueryBuilder()
->select(['p', 'o'])
->from('AppBundle:PriceOption', 'p')
->innerJoin('p.offer', 'o')
->getDQL();

关于php - DQL 子查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43726719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com