在CakePHP 3.x中订购'Contain'模型

Ise*_*ngo 10 model contain cakephp-3.x

我有多个Things在AnotherThing此,我想订购他们在我的编辑操作在我的AnotherThing Controller-我可以访问Things我的编辑就好了,但我想他们不同的排序(不超过他们的ID),例如Things.pos

什么是最好的做法?我试过了

public $hasMany = array(
        'Thing' => array(
            'order' => 'Thing.pos DESC'
        )
    );
Run Code Online (Sandbox Code Playgroud)

但没有改变.任何的想法?

Ise*_*ngo 26

重读文档.抱歉!

无论如何,如果有人寻找答案,这里是:http: //book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#sorting-contained-associations

编辑:

加载HasMany和BelongsToMany关联时,可以使用sort选项对这些关联中的数据进行排序:

$query->contain([
    'Comments' => [
        'sort' => ['Comment.created' => 'DESC']
    ]
]);
Run Code Online (Sandbox Code Playgroud)