cakephp null value on condition

jv2fixgn  于 2023-04-06  发布在  PHP
关注(0)|答案(4)|浏览(174)
$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。

5tmbdcev

5tmbdcev1#

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

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

nue99wik2#

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

将每个team_id条件 Package 在它自己的数组中。这可以防止出现重复的team_id数组键,同时仍然为条件使用一致的格式。

knsnq2tg

knsnq2tg3#

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

这就是你想要的。

6tr1vspr

6tr1vspr4#

$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',

);

相关问题