2011-01-20 69 views
0

我試圖做一個非常簡單的CakePHP找到使用中可容納的行爲:的CakePHP中可容納:模型「比較」是不是與模型「比較」相關

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id), 
    'contain' => array(
     'Comp.id' => array(
      'fields' => array('Comp.id'), 
     ), 
     'Slot' => array(
      'fields' => array(
       'Slot.start_time', 
       'Slot.end_time' 
      ) 
     ), 
     'Team' 
    ) 
)); 

...但在執行時會顯示警告信息:

警告(512):型號 「小樣」 並不 與模型 「小樣」 [CORE /蛋糕/庫/模型/行爲/ containable.php, 線363]相關聯

我比較模式的開始如下:

var $name = 'Comp'; 
var $hasMany = array('Team', 'Round', 'Match'); 
var $belongsTo = array('Generation'); 
var $hasAndBelongsToMany = array('Slot'); 
var $actsAs = array('Containable'); 

我使用CakePHP 1.3.6

任何想法可能會導致什麼呢?

回答

3
$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id), 
    'fields'  => array('Comp.id'), 
    'contain' => array(
     'Slot'  => array(
      'fields'  => array(
       'Slot.start_time', 
       'Slot.end_time' 
      ) 
     ), 
     'Team' 
    ) 
)); 

你告訴它contain相關Comp.id,這意味着相關Comp模型Comp,它不存在。您可能只想設置Comp模型本身的fields選項?

+0

非常感謝!我不認爲要保持根模型的字段分離。 – Ben 2011-01-20 02:47:26