2012-01-04 18 views
0

我正在處理一些相當不好的繼承代碼,並且有一個查詢從表中拉取事件。事件模型有$hasOne = array('blocked'); - 我的目標是隻返回在阻止表中沒有條目的所有事件。儘管設置了$ hasOne,但蛋糕仍然單獨查詢阻止的事件表,因此我無法將這些字段用作條件。hasOne對於cakephp find來說爲null條件()

查詢本身已經在'contains' => ...之內,因此使用'joins' => ...手動強制加入不起作用。

更新:這裏是查找查詢,因爲它現在已經存在:

$params = array(
    'conditions' => array(
     'Restaurant.id' => $id, 
     'Restaurant.inactive' => 0, 'Restaurant.deleted' => 0, 
     'Restaurant.bkwindow <=' => (strtotime($criteria['Restaurant']['date']) - strtotime("today"))/86400 
    ), 
    'fields' => array(), 
    'contain' => array(
     'Experience' => array(
      'Experience_blocking' 
     ) 
    ) 
); 

我需要的經驗表只返回沒有在Experience_blocking表項結果。經驗是用$ hasOne of Experience_blocking設置的,但它永遠不會工作,它總是將它作爲一個可容納的查詢。

回答

0

因爲你不顯示太多的代碼,我會嘗試猜測你的問題是什麼,並且是冗長的。您無法使用可包含的行爲執行您想要的操作。

如需更詳細的答案,請參閱this post