-
-
Notifications
You must be signed in to change notification settings - Fork 906
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
How to override default ordering with an order filter #2690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The default order is used to ensure a stable ordering of items, as otherwise the order is undefined as per the SQL standard. I don't see any case where you should have a need to remove the default order when using custom ordering. |
It does not seem to be supported at this time: https://github.com/api-platform/core/blob/v2.4.2/src/Bridge/Doctrine/Orm/Extension/OrderExtension.php#L54
|
Let me put it this way. The user should be able to order collection by using a specific order filter. If no filter is used the collection should be ordered by default order. |
Sorry, I don't understand. The default order is exactly what that's for? I've already explained above why the default order is always added to the end. You should choose something that is definitely able to order items to avoid running into undefined ordering. To give you an example, if the user chooses to order by |
In fact, the default order is not used by the |
Keeping open for this. |
Hi teohhanhui, thanks for your input and clarification. I understand the difference between OrderExtension and FilterExtension. However, I'm not really sure if we have an understanding. Let's assume we have a simple entity, just for the sake of example.
ApiPlatform resource definition:
Filter service
when querying /api/bars API endpoint the api_platform data provider would generate something like this (approximation, writing from top of my head)
When querying /api/bars?order[name]=asc&order[description]=desc the query would look like this (not really sure about order of ORDER clause identifiers):
Either way, default order is unnecessary applied. For huge tables this would present an overhead at database level and eventually wrong ordering. Sorry if I make this unnecessary difficult or if I don't see a solution out-of-the-box. A potential solution that does not touch any api-platform implementation is to decorate OrderExtension and detect if order filter is being activated, before or after the OrderFilter is processed. |
If anyone stumbles upon the same problem this gist has the solution mentioned in previous post. |
Same problem here, I write a filter that add a custom "distinct" capatibility, managable by HTTP GET queries ; but when we use the "distinct" method of queryBuilder, "orderBy" have to follow same list and same order as distinct properties. EDIT |
I have the same problem with Doctrine ODM. Adds ordering by
|
Correction from my side: there is no need to disable default ordering. If you check |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi everyone!
I've added default ordering to resource attributes (yaml). So far so good.
However, the default order is still applied when querying the collection with an explicit order filter (query param).
The query builder used by data provider orders by default and by order filter.
Is there a way to ditch default order when order filter has been activated?
Also is it possible to define default order at operation level?
The text was updated successfully, but these errors were encountered: