I was wondering if there is a way to declare the default order for my doctrine models.
e.g.
I have a work model and it has photos. When I load a work, all photos associated to it get loaded into $work->photos. When I display them, they are ordered by their IDs.
It would be very convenient to declare a default order on another field or perhaps override the fetch behaviour altoghether.
I’d rather not to convert the photos to an array and use usort. Thanks.
You can specify it in the YAML as follows:
If it’s a sorting order for a field in the table itself add:
where
options:is at the same depth as you’d have acolumns:orrelations:entry. NB: The capitalisation oforderBy:is vital; get it wrong and you’ll get no error but also no sorting.If it’s a sorting order for a relationship then, within the relationship you can skip the
options:part and just put in: