这个查找条件有什么问题

时间:2012-07-31 14:36:42

标签: php cakephp

以下工作,它为我提供了删除为空的所有数据:

$conditions = array('OR' => array(

    'Task.deleted' => null,


    )

);


$this->set('tasks', $this->Task->find('all', array('recursive' => 2, 'conditions' => $conditions)));

类似下面给出了删除为0的所有数据

$conditions = array('OR' => array(

 'Task.deleted' => 0,


)

); //...

但如果我像下面这样组合它,它会给我删除的数据为空,但不包括删除的数据为0。

$conditions = array('OR' => array(

        'Task.deleted' => 0,
        'Task.deleted' => null

        )

);

2 个答案:

答案 0 :(得分:4)

您正尝试将PHP数组键'Task.deleted'设置两次,覆盖它。请执行以下任一操作:

'Task.deleted' => array(0, null)

或:

'OR' => array(
    array('Task.deleted' => 0),
    array('Task.deleted' => null)
)

答案 1 :(得分:0)

阅读本文

http://book.cakephp.org/1.3/view/1030/Complex-Find-Conditions

$conditions = array(
    'OR' => array(
       array('Task.deleted' => 0),
      array('Task.deleted' => null)
    )
    );

$this->set('tasks', $this->Task->find('all', array('recursive' => 2, 'conditions' => $conditions)));