首页 > 解决方案 > Cakephp 找到空值

问题描述

我想让每个拥有空字段的人。

我尝试了以下但它没有返回任何东西。

$plato = $this->Platos->find('all',[
            'conditions' => ['alergia_id' => null]
        ]);

标签: listcakephpfind

解决方案


在 SQLnull中不等于(=)任何东西——甚至不等于另一个 null. 根据 SQL 的三值逻辑,结果 null = null不为真但未知。SQL 具有is [not] null 用于测试特定值是否为空的谓词。

https://modern-sql.com/feature/is-distinct-from

这就是解决方案。

$plato = $this->Platos->find('all',[
            'conditions' => ['alergia_id IS null']
        ]);

推荐阅读