cakephp条件为null值

时间:2012-02-01 08:37:04

标签: cakephp

 $this->paginate['Member'] = array(
        'conditions' => array($conditions,'Member.division_id' => $currentTeam['Division']['id'],'Member.team_id'=> array(null,0)),
        'group' => 'Member.id',

    );

此查询不会获得NULL团队ID。它只获得团队ID 0。

4 个答案:

答案 0 :(得分:11)

使用IS NULL关键字通常有效。

array( 
    $conditions,
    'Member.division_id' => $currentTeam['Division']['id'],
    'OR' => array(
        'Member.team_id' => 0,
        'Member.team_id IS NULL'
    )
)

答案 1 :(得分:9)

你能试试吗?

$this->paginate['Member'] = array(
        'conditions' => array($conditions,
                'Member.division_id' => $currentTeam['Division']['id'],
                'OR'=> array(
                   array('team_id'=>null), 
                   array('team_id'=>0),
                ),
        'group' => 'Member.id',

);

编辑:在其自己的数组中包含每个team_id条件。这可以防止出现重复的“team_id”数组键,同时仍然使用一致的条件格式。

答案 2 :(得分:2)

array( 
   $conditions,
   'Member.division_id' => $currentTeam['Division']['id'],
     'OR' => array(
        'Member.team_id' => 0,
        'IS' => array( 'Member.team_id' => NULL )
     )
 )

这就是你想要的。

答案 3 :(得分:0)

$this->paginate['Member'] = array(
        'conditions' => array($conditions,
                'Member.division_id' => $currentTeam['Division']['id'],
                'OR'=> array('Member.team_id'=> null, 'Member.team_id'=> 0),
                'group' => 'Member.id',

);