我想在 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'));
}
两者在单独使用时按预期工作,但不能一起使用。如何组合它们?
使用点表示法。假设项目状态链接到任务到,请尝试以下操作:
$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'));