2012-02-01 58 views
2
$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爲0CakePHP的空值

回答

8

你可以試試這個?

$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」數組鍵,同時仍然對條件使用一致的格式。

+1

這怎麼可能是一個正確的答案? OR數組有重複鍵'team_id',所以這個值總是隻有0,null會丟失 – Ceeram 2013-10-04 13:35:12

+0

現在有人修復它,看起來好像。 – mark 2015-11-01 22:32:25

10

使用IS NULL關鍵字通常有效。

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

這很好,thx! – FAjir 2014-02-12 09:12:32

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

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

這是你想要的。