CakePHP包含:模型“Comp”与模型“Comp”无关

时间:2011-01-20 02:38:58

标签: cakephp warnings cakephp-1.3 behavior containable

我正在尝试使用Containable行为进行相当简单的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):型号“Comp”不是   与模型“Comp”相关联   [CORE /蛋糕/库/模型/行为/ containable.php,   第363行

我的Comp模型的开头如下:

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

可能导致此问题的任何想法?

1 个答案:

答案 0 :(得分: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不存在。您可能只想设置fields模型本身的Comp选项?