Symfony2学说NotIn问题

亚当

我无法弄清楚我在做什么错。我正在做一个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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Symfony2 notIn不起作用

来自分类Dev

symfony2学说oneone完整示例

来自分类Dev

Symfony2学说关联结果

来自分类Dev

ManyToOne作为ID的学说(symfony2)

来自分类Dev

Symfony2学说抛出NonUniqueResultException

来自分类Dev

使用YAML的Symfony2学说索引

来自分类Dev

Symfony2学说实体未水合

来自分类Dev

Symfony2学说Querybuilder全选

来自分类Dev

Symfony2学说manyToOne EntityNotFoundException

来自分类Dev

Symfony2与学说:findBy的嵌套条件

来自分类Dev

Symfony2学说创建查询

来自分类Dev

Symfony2学说关联结果

来自分类Dev

Symfony2:学说MySql数学函数

来自分类Dev

从symfony2学说的结果中获取对象的价值

来自分类Dev

Symfony2学说在next()中进行迭代

来自分类Dev

Symfony2学说Qb STR_TO_DATE未知函数

来自分类Dev

Symfony2学说无法识别的字段:

来自分类Dev

Symfony2学说,如何仅获取特定表的列名

来自分类Dev

Symfony2学说将计数全部作为整数

来自分类Dev

将mongodb命令转换为学说格式Symfony2

来自分类Dev

实体和MySQL中的学说数组类型(Symfony2)

来自分类Dev

symfony2:带有学说的本机查询

来自分类Dev

Symfony2学说ORM级联分离不起作用

来自分类Dev

Symfony2学说:如何禁用mysql连接?

来自分类Dev

Symfony2学说1062重复输入

来自分类Dev

Symfony2学说一对一映射

来自分类Dev

getRepository在foreach循环中失败,Symfony2学说

来自分类Dev

SQL转换为ORM学说Symfony2

来自分类Dev

PdoSessionHandler的Symfony2问题