我正在尝试从供应商所经过的表o
分配 *。(这是在学说存储库的上下文中(。然后,我想运行一个子查询和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();
}
这是错误:AppBundleTestsServiceVendorServiceTest::testGetVendorFeaturedDeals
DoctrineORMQueryQueryException: [Syntax Error] line 0, col 18: Error: Unexpected 'FROM'
由DoctrineORMQueryQueryException: SELECT o, (SELECT FROM AppBundle:PriceOption p INNER JOIN p.offer o) FROM AppBundleEntityOffer o WHERE o.vendor = :vendor
任何帮助将不胜感激,谢谢!
您应该将查询修改为:
$purchaseOptions = $this->
getEntityManager()
->createQueryBuilder()
->select(['p', 'o'])
->from('AppBundle:PriceOption', 'p')
->innerJoin('p.offer', 'o')
->getDQL();