Search code examples
cakephp

cakephp null value on condition


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

    );

This query does not get the NULL team id.. It gets just the team id 0.


Solution

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

    Wrapped each team_id condition in it's own array. This prevents the issue of a duplicated team_id array key, while still using a consistent format for the conditions.