这是我的模型:
class Question extends AppModel {
public $hasMany = array(
'CaseQuestions' => array('className'=>'Question', 'foreignKey'=>'parent_id')
);
public $hasOne = array(
'CaseStudy' => array('className'=>'Question', 'foreignKey'=>'parent_id')
);
这是我的控制器中的操作:
public function admin_delete_case_question($question_id) {
$this->Question->Behaviors->load('Containable');
$this->Question->contain( array('CaseStudy'));
$question = $this->Question->findById($question_id );
debug($question);
exit;
上面的调试返回如下内容:
array(
'Question' => array(
'id' => '78',
'nickname' => '',
'content' => 'sdgsdfgs',
'type' => 'CQ',
'option1' => 'sdfgsdfg',
'option2' => '',
'option3' => '',
'option4' => '',
'time' => '-1',
'difficulty' => '0.0000',
'slope' => '0.0000',
'chance' => '0',
'experiment' => false,
'created' => '2013-05-02 16:30:29',
'modified' => '2013-05-02 16:30:29',
'status' => null,
'perm_id' => '76',
'notes' => null,
'is_deleted' => false,
'answer_id' => '0',
'parent_id' => '77',
'order' => null
),
'CaseStudy' => array(
'id' => null,
'nickname' => null,
'content' => null,
'type' => null,
'option1' => null,
'option2' => null,
'option3' => null,
'option4' => null,
'time' => null,
'difficulty' => null,
'slope' => null,
'chance' => null,
'experiment' => null,
'created' => null,
'modified' => null,
'status' => null,
'perm_id' => null,
'notes' => null,
'is_deleted' => null,
'answer_id' => null,
'parent_id' => null,
'order' => null
)
)
我不明白为什么 CaseStudy 数组全部为 NULL,因为当我查看数据库中的该记录(id 77)时,所有数据都是正确的。我究竟做错了什么?