开发者

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

I am using Doctrine 1.1 in Zend. I am trying to write开发者_JS百科 a query that will return records that have a null value in a certain column.

    $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 NULL value in the vertical_id column yet the query doest not find these.

Appreciate the help.

Sid.


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

where('a.vertical_id is NULL');


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

->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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜