When using contain
, CakePHP performs several queries , as many as are included. So you can not perform conditions, sort, group, and so on in your main class from contain
classes.
So if your class that will be paged is the PointCollect , it's the one you can sort in the order key you placed in your code.
Now you can sort Units that are contained in PointCollect , which is to include the order , like this:
$this->paginate = [
'contain' => ['Unidades' => ['order' => ['Unidades.nome' => 'DESC']]],
'fields' => ['PontoDeColetas.id','PontoDeColetas.nome','PontoDeColetas.status','Unidades.id','Unidades.nome']
];
Otherwise, you'll have to use joins
. , that's a bit different from the solution.