php-crud-api
php-crud-api copied to clipboard
Sort on related field
Hi @mevdschee ! In a many-to-many scenario, how can I sort on a related field?
You cannot sort on a related field as the implementation is streaming (and thus does not use joins). This means that the entities are streamed to the client one by one. So once the related items are requested, the base entity has already been sent to the client.
If you use transform on the server (which is not intended use), then the results are collected and combined on the server. We might allow for sorting afterwards, but it is not the same as the sort (SQL order) that you can apply on the base entity.
Maybe we can introduce a new concept of "sort" that can be applied after transformation, as opposed to "order" which is applied before.
good idea :) ! So for now, sorting on client-side by manipulating the json objects order.
Yes indeed. I'll keep this issue open as a reminder for the feature.