I have many tables with sortable headers in the frontend. When any of them is clicked, a request similar to
http://localhost:8080/api/v1/items/?page=0&size=10&sort=item.type.name,asc&itemId=4
is sent to the backend where it gets automatically mapped to a Pageable object and goes to a Repository.
Notice the item.type.name
part. If relationships are relatively simple, this works but does not feel like a good way to do it.
What if I need to compare against a property of an object which is inside a collection?
What is the best practice to sort by values from lists like errors
in the item.order.errors.name
example, when the relationship is one to many?
I'm afraid writing sorting headers like item.type.name
or even a.b.c.d.e.f.g
in a bad scenario, creates a very tight coupling where it will be difficult to change or refactor code in the future without breaking anything.