Feature #88734
openExtbase: M:N Relation – Sorting of Child Model Records by $defaultOrderings
0%
Description
In an M:N relation, the $defaultOrderings
as defined in the model repositories should be taken into account – at least in case the parent_child_mm.sorting
property is set to 0.
Explanation/Example:
I have an extension with two models that are m:n related. You can edit the relations from both sides by use of a selectCheckBox
list of records. The child model is always supposed to be sorted by a date field in ORDER_DESCENDING, as defined in the model’s repository:
protected $defaultOrderings = ['date_open' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING];
The frontend detail view of the parent model shows the related records of the child model. The sorting is correct when I select the relation from the parent model record as T3 stores the sorting in parent_child_mm.sorting
. This sorting order is defined by the TCA setting of the selectCheckBox
, thus the order of the checkboxes in the backend form.
But if I only select the relation in the child model records (and thus parent_child_mm.sorting=0
), the sorting in the frontend detail view is random: in my local development version it’s correct, in the production version it’s not (I reckon, it’s being sorted by uid::ASC).
I’ve been searching for ways to determine the sorting in the frontend. Some suggested the <v:iterator.for>
viewhelper – but I think it should not be set in the view but in the controller or repository. And besides I don’t want to have the additional dependency on ext_vhs. Others suggested to create a specific repository method in the child model – but they referred to old T3 versions and I couldn’t make those ideas work in T3v9.
I think the $defaultOrdering
should be taken into account – after all, it’s what the property name DEFAULT ORDERING suggests.