find不返回关联的模型数据cakePHP

时间:2014-10-14 07:25:56

标签: cakephp has-many multiple-tables model-associations belongs-to

模型问答

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匹配的问题。

我想在单个查找查询中获取问题以及答案。

0 个答案:

没有答案