I got deep associations and i wanted to know if it's possible to order result by a field contained in a BTM association:
$modeles = $this->Caracteristiques
->find()
->contain(['ModeleElements.ModeleOuvrages' => function ($q) {
return $q
->where([
'ModeleOuvrages.couche_id' => 2,
'ModeleOuvrages.compte_client_id' => $this->Auth->user('compte_client_id')
]);
}]);
Here is my query, i want a resultSet order by the field "nom" in "ModeleOuvrages" association.
Is it possible to get all "caracteristiques" order by "ModeleOuvrages.nom" ?
Edit: i did this:
$modeleOuvrages = $this->ModeleOuvrages
->find()
->where([
'couche_id' => 2,
'compte_client_id' => $this->Auth->user('compte_client_id')
])
->select([
'ModeleOuvrages.nom',
'ModeleElements.nom',
'Caracteristiques.nom',
'Caracteristiques.type'
])
->matching('ModeleElements.Caracteristiques')
->order(['ModeleOuvrages.nom', 'ModeleElements.nom', 'Caracteristiques.nom']);
and it works well. We can also do this with contain with more verbose.