如何使用 Doctrine 查询 NOT NULL? [英] How to query NOT NULL with Doctrine?

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

问题描述

我有表测试:

Test:
id | name 
1  | aaa
2  | 
3  | ccc
4  | aaa
5  | 
6  | ddd

我想要名称不为 NULL 的结果:

I want result where name is NOT NULL:

aaa
ccc
aaa
ddd

我怎样才能得到:

Doctrine_Core::getTable('Test')->findBy('name', NOTNULL??) <-doesnt working

在模型中:

$this->createQuery('u')
     ->where('name = ?', NOTNULL ???) <- doesnt working
     ->execute();

推荐答案

试试这个:

$this->createQuery('u')
     ->where('name IS NOT NULL')
     ->execute();

这是标准的 SQL 语法.Doctrine 不会将 Null 值转换为正确的 sql.

which is standard SQL syntax. Doctrine doesn't convert Null values into proper sql.

这篇关于如何使用 Doctrine 查询 NOT NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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