从自定义命名的aossciation中选择所有字段

时间:2017-04-24 08:24:29

标签: php cakephp cakephp-3.0

我有这样的查询:

    $q = $q  
        //->select($this->LessonPupils) // Does not work
        ->select([
            'OutLessonPupils.*', // Does not work
            'Groups.id', 
        ])
        ->where($conditions)
        ->order($order)
        ->contain([
            'Pupils',
            'Pupils.Groups',
            'Pupils.OutLessonPupils'
        ]);

我想从Pupils关联OutLessonPupils中选择使用LessonPupils表格类的所有字段,但我似乎无法使其工作,我在文档中找不到任何内容关于这个。

如何从OutLessonPupils中选择所有字段?

1 个答案:

答案 0 :(得分:2)

需要通过调用协会->select($this->Pupils->OutLessonPupils)来选择您的代码

$q = $q->select($this->Pupils->OutLessonPupils)
        ->select([
            'Groups.id', 
        ])
        ->where($conditions)
        ->order($order)
        ->contain([
            'Pupils',
            'Pupils.Groups',
            'Pupils.OutLessonPupils'
        ]);