本文介绍了教义返回错误为"eq",否为"in".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Symfony和Doctrine,"eq"子查询出现错误:
With Symfony and Doctrine, I have an error with "eq" subquery :
没关系,没有错误:
public function getForums()
{
$qb = $this->createQueryBuilder('fc');
return $qb
->innerJoin('fc.versions', 'fcv')
->innerJoin('fc.versions', 'fcvl', 'WITH', $qb->expr()->in(
'fcvl.id',
$this->_em->createQueryBuilder()
->select('MAX(v.id)')
->from(ForumCategoryVersion::class, 'v')
->where('v.forumCategory = fc')
->getDQL()
))
->select('fc, fcv')
->getQuery()
->getResult();
}
用 eq
替换 in
:
Replace in
by eq
:
public function getForums()
{
$qb = $this->createQueryBuilder('fc');
return $qb
->innerJoin('fc.versions', 'fcv')
->innerJoin('fc.versions', 'fcvl', 'WITH', $qb->expr()->eq(
'fcvl.id',
$this->_em->createQueryBuilder()
->select('MAX(v.id)')
->from(ForumCategoryVersion::class, 'v')
->where('v.forumCategory = fc')
->getDQL()
))
->select('fc, fcv')
->getQuery()
->getResult();
}
我遇到此错误:
推荐答案
您需要对子查询使用括号 ():
->innerJoin('fc.versions', 'fcvl', 'WITH', $qb->expr()->eq(
'fcvl.id',
'(' . $this->_em->createQueryBuilder()
->select('MAX(v.id)')
->from(ForumCategoryVersion::class, 'v')
->where('v.forumCategory = fc')
->getDQL() . ')'
))
参考
这篇关于教义返回错误为"eq",否为"in".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!