模型问答
class Question extends AppModel {
public $name = "Question";
public $useTable = "questions";
public $primaryKey = 'question_id';
public $hasMany = array(
'Answer' => array(
'className' => 'Answer',
'foreignKey' => 'question_id',
'dependent' => true
)
);
}
class Answer extends AppModel {
public $name = "Answer";
public $useTable = "answers";
public $primaryKey = 'answer_id';
public $belongsTo = array(
'Question' => array(
'className' => 'Question',
'foreignKey' => 'question_id',
)
);
}
在数据库中
答案 answer_id question_id 文本
问题 question_id skill_id也 文本
控制器中的
$ questions = $ this->问题 - >查找('所有',数组('条件' =>数组(' skill_id' = > $ skills)));
没有给我答案,它只返回与技能ID匹配的问题。
我想在单个查找查询中获取问题以及答案。