php 如何在 Doctrine 查询中指定空值作为过滤器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5154383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:58:03  来源:igfitidea点击:

How to specify null value as filter in a Doctrine query?

phpnulldoctrinedql

提问by Mr B

I am using Doctrine 1.1 in Zend. I am trying to write a query that will return records that have a null value in a certain column.

我在 Zend 中使用 Doctrine 1.1。我正在尝试编写一个查询,该查询将返回在特定列中具有空值的记录。

    $q = Doctrine_Query::create()
    ->select('a.*')
    ->from('RuleSet a')
    ->where('a.vertical_id = ?', null);

    $ruleset_names_result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);

I have three records in the ruleset table which have a NULLvalue in the vertical_id column yet the query doest not find these.

我在规则集表中有三个记录,它们在 vertical_id 列中有一个NULL值,但查询没有找到这些。

Appreciate the help.

感谢帮助。

Sid.

席德。

回答by Johannes

I use doctrine with symfony, and this is how I do:

我在 symfony 中使用了学说,这就是我的做法:

where('a.vertical_id is NULL');

where('a.vertical_id is NULL');

回答by John Carlos Espitia Rivera

If you are using Symfony 2 and above, you can use this code:

如果您使用的是 Symfony 2 及更高版本,则可以使用以下代码:

->where($qb->expr()->isNull('a.vertical_id'));

Reference:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#the-expr-class

参考:http:
//docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#the-expr-class