Symfony2 Doctrine Expr'IS NOT NULL' [英] Symfony2 Doctrine Expr 'IS NOT NULL'

查看:163
本文介绍了Symfony2 Doctrine Expr'IS NOT NULL'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的实体的FormType,并设置一个实体字段
我需要一个And中的两个Where子句,以及我在查询生成器页面,至少我应该如何处理:

I'm using the FormType for an Entity of mine, and setting up an entity field. I need two Where clauses in an And, and from what I've read on the Query Builder page, this is at least how I should go about it:

'query_builder' => function ($er){
    $qb = $er->createQueryBuilder('p');
    $qb
        ->where($qb->expr()->andx(
            $qb->expr()->in('p', '?1'),
            $qb->expr()->not(
                $qb->expr()->eq('p.location', 'NULL')
            )
        ))
        ->setParameter(1, $this->totalScope)
    ;
    return $qb;
},

然而, not(eq ','NULL'))没有达到所需的结果(实际上,错误是Error:Expected Literal,got'NULL'

However, the not(eq('col', 'NULL')) doesn't achieve the desired result(and in fact, errors with "Error: Expected Literal, got 'NULL'"

推荐答案

您可以使用 isNotNull

You can use isNotNull:

'query_builder' => function ($er){
    $qb = $er->createQueryBuilder('p');
    $qb
        ->where($qb->expr()->andx(
            $qb->expr()->in('p', '?1'),
            $qb->expr()->isNotNull('p.location')
        ))
        ->setParameter(1, $this->totalScope);

    return $qb;
},

这篇关于Symfony2 Doctrine Expr'IS NOT NULL'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆