using cakephp 2.
I have a model called pupils which
$hasMany = array('PupilAction', 'TransientAction', 'TriageEvent')
and
$belongsTo = array('FormClass')
in my PupilsController I have the baked
$this->set('pupil', $this->Pupil->read(null, $id));
I’d like to order the resulting related data, specifically the $hasMany = array(‘PupilAction’, ‘TransientAction’, ‘TriageEvent’) elements, by the field in each of those tables named date. I also want to include the full amount of info, I don’ want to restrict any fields from being returned, just to have those three tables ordered by date.
I can’t find a good example of how to use read() – most people seem to use find but I’d like to figure out this read one.
Can anyone kindly enlighten me?
If you always need that data ordered by date, then in each model’s PHP file add the $order variable.
or
This will ensure that those models return ordered results for associations, pagination and finds by default.
Otherwise, you can use the order key for the containable behavior. Ensure you add the Containable behavior to the $actAs for each model (or in your AppModel.php)