To add some context, this is in steps my service (called by the controller) building the array of order+lines to hand over to the template.
Prereqs
1) every model holds also a boolean per field if it is available for sorting and/or searching on
2) all methods used in the chain 'controller -> service -> repository -> model <- Cortex' after the 'controller' support the $options and $filters params to be used by Cortex
Process
1) call is made to controller->index(), which calls service->index()
2) search or sort is set via $options and $filters to the service->index() as they should
3a) when sorting is detected in $options the service checks with the model if there is a relation for the field it needs to sort on
3b) if no relation then sort created by setting field and direction
3c) if it is a relation then the fieldname is set as '@fieldname.relatedModelName'
4a) when searchables fields available in model and searched term is detected search filter code is built
4b) if yes the searchable fields are listed and per field checked if they are from a relation - a WHEN {target} LIKE ... THEN filter is built (weighted search)
4c) {target} for regular fields is table.field, for 'belongs-to-one' relation (what all this is for) it builds RelationTable__RelationField.relationFieldName
(which is picked up by the JOIN mentioned earlier)
4d) added to the order part (which is the end of the query) is a CASE .... ELSE END query part to calculate the weight and use it as primary sorting
5) pass end result of $options and $filter to ->paginate()
6) return the rows and totalrows quantity ready to be used in the template
I hope this clearifies a bit :-)
Op vrijdag 30 september 2022 om 10:54:51 UTC+2 schreef BQ VOR: