简体   繁体   English

CakePHP Containable在“有很多”关系中未返回正确的结果

[英]CakePHP Containable doesn't return correct results in “has many” relation

Someone can tell me why it doesn't work: 有人可以告诉我为什么它不起作用:

$data = $this->Question->find('all', array(
                             'conditions' => array(
                                               'Question.id' => $qid
                                             ),
                             'contain' => array(
                                            'Slide' => array('Training')
                                          )
                   ));

Relation is as follows: 关系如下:

Training -> has_many -> Slide -> has_many -> Question

So Why result is something like that: 那么为什么结果是这样的:

 [0] => Array
    (
        [Question] => Array
            (
                [id] => 1
            )
        [Slide] => Array
            (
                [id] => 1320
            )
    )

You're calling #find on the Question model. 您正在对问题模型调用#find。 So, you need to define the relationships from Question to Slide and from Slide to Training to include them in your results. 因此,您需要定义从问题到幻灯片以及从幻灯片到培训的关系,以将它们包括在结果中。 Try adding Question belongsTo Slide and Slide belongsTo Training. 尝试添加“问题归属于幻灯片”和“幻灯片归属于培训”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM