When using contain
, the Cakephp performs several darlings, as many as are included. Then you cannot perform conditions, sort, group and etc in your main class from the contain
.
So if your class that will be paginated is the Pontodecoletas, she’s the one you can order in the key order that you put in your code.
Now, you can order Units which are contained in Pontodecoletas, which includes only the order, thus:
$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
, then the solution is a little different.
Perfect, it seems to be a new feature of Cakephp 3, I didn’t know. You can mark your own answer as the correct one in this case.
– Paulo Rodrigues