我无法弄清楚我在做什么错。我正在做一个notin查询,在此之后,我将跟踪我发现的所有堆栈溢出帖子,这些帖子说先创建notin查询,然后再将其放入实际查询中。这是我要运行的查询。
public function loadCompleted()
{
$notIn = $this->getEntityManager()->createQueryBuilder()
->select('DISTINCT j.id')
->from($this->getEntityName(), 'j')
->join('NucleoManagerBundle:JobStatus', 'js', Join::WITH, 'j.jobStatus = js.id')
->join('NucleoManagerBundle:Task', 't', Join::WITH, 't.job = j.id')
->join('NucleoManagerBundle:TaskStatus', 'ts', Join::WITH, 't.taskStatus = ts.id');
$notIn->where('ts.draft = 1')
->orWhere('ts.pending = 1')
->orWhere('ts.depending = 1')
->orWhere($notIn->expr()->andX(
$notIn->expr()->eq('ts.draft', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.completed', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.pending', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.invoiced', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.cancelled', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.depending', $notIn->expr()->literal(false))
))
->getQuery()
->getResult();
$query = $this->getEntityManager()->createQueryBuilder()
->select('j')
->from($this->getEntityName(), 'j')
->join('NucleoManagerBundle:JobStatus', 'js', Join::WITH, 'j.jobStatus = js.id')
->where('j.billable = 1')
->andWhere('j.invoiced = 0')
->andWhere('j.template = 0')
->andWhere('js.invoiced = 0')
->andWhere('js.cancelled = 0');
$query->andWhere($query->expr()->notIn('j.id', $notIn));
return $query->getQuery()->getResult();
}
我收到以下错误:
ContextErrorException: Catchable Fatal Error: Object of class Doctrine\ORM\EntityManager could not be converted to string in C:\BitNami\wampstack-5.4.24-0\apps\manager\htdocs\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr\Func.php line 76
任何人都可以帮忙吗?提前致谢!
看起来我已经通过这篇文章弄清楚了如何做到这一点:doctrine2 notIN Function中的子查询。我在notin查询上使用getDQL函数,并确保我的所有别名都不与常规查询的别名一致。
public function loadCompleted()
{
$notIn = $this->getEntityManager()->createQueryBuilder()
->select('DISTINCT j')
->from($this->getEntityName(), 'j')
->join('NucleoManagerBundle:JobStatus', 'js', Join::WITH, 'j.jobStatus = js.id')
->join('NucleoManagerBundle:Task', 't', Join::WITH, 't.job = j.id')
->join('NucleoManagerBundle:TaskStatus', 'ts', Join::WITH, 't.taskStatus = ts.id');
$notIn->where('ts.draft = 1')
->orWhere('ts.pending = 1')
->orWhere('ts.depending = 1')
->orWhere($notIn->expr()->andX(
$notIn->expr()->eq('ts.draft', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.completed', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.pending', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.invoiced', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.cancelled', $notIn->expr()->literal(false)),
$notIn->expr()->eq('ts.depending', $notIn->expr()->literal(false))
));
$query = $this->getEntityManager()->createQueryBuilder()
->select('job')
->from($this->getEntityName(), 'job')
->join('NucleoManagerBundle:JobStatus', 'jstatus', Join::WITH, 'job.jobStatus = jstatus.id')
->where('job.billable = 1')
->andWhere('job.invoiced = 0')
->andWhere('job.template = 0')
->andWhere('jstatus.invoiced = 0')
->andWhere('jstatus.cancelled = 0');
$query->andWhere($query->expr()->notIn('job.id', $notIn->getDQL()));
return $query->getQuery()->getResult();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句