CakePHP 3.6.17:预加载排序

CakePHP 3.6.17: Eager loading with sorting

我想在 cakephp 3.6 中结合预先加载和排序

在我的控制器中,我可以使用预先加载或排序方式,但我不能将它们结合起来。这是我的代码:

预加载:

    $user = $this->Users->get($id, [
        'contain' => [ 'TasksTo' => ['ProjectStatus']]
    ]); 
    $this->set(compact('user'));

排序:

    $user = $this->Users->get($id, [
        'contain' => ['TasksTo'  => ['sort' => ['TasksTo.priority' => 'ASC']]]); 
    $this->set(compact('user'));
}

当单独使用但不一起使用时,两者都能按预期工作。我该如何组合它们?

使用点符号。假设 ProjectStatus 链接到 TasksTo,试试这个:

$user = $this->Users->get($id, [
    'contain' => ['TasksTo.ProjectStatus' => ['sort' => ['TasksTo.priority' => 'ASC']]]); 
$this->set(compact('user'));

好吧,我是这样修复的:

$user = $this->Users->get($id, [
    'contain' => ['TasksTo' => ['ProjectStatus', 'sort' => ['TasksTo.priority' => 'ASC']]]); 
$this->set(compact('user'));