API Platform version(s) affected: 4.1.7
Description
When a default ordering is defined in api_platform.yaml, and an ApiResource defines an order in the #[ApiResource] annotation, the default order still remains in the SQL query as the first ordering criterion. The ApiResource ordering is only appended instead of replacing the default.
How to reproduce
- Have an ApiResource with at least two fields, e.g. a resource
Event with two timestamps $createTime and $startTime
- In api_platform.yaml, set
api_platform.defaults.order to the value createTime
- In the
#[ApiResource()] annotation, add order: ['startTime']
- Fetch all Events and observe the generated SQL query in the profiler
Expected order clause in the SQL query: ORDER BY start_time ASC
Actual order clause in the SQL query: ORDER BY create_time ASC, start_time ASC
Possible Solution
Setting an order on the ApiResource should completely replace the default defined in api_platform.yaml. A default should not be forced onto every query, it should only provide a fallback in case no other, more specific value is chosen.
Additional Context
API Platform version(s) affected: 4.1.7
Description
When a default ordering is defined in api_platform.yaml, and an ApiResource defines an
orderin the#[ApiResource]annotation, the default order still remains in the SQL query as the first ordering criterion. The ApiResource ordering is only appended instead of replacing the default.How to reproduce
Eventwith two timestamps$createTimeand$startTimeapi_platform.defaults.orderto the valuecreateTime#[ApiResource()]annotation, addorder: ['startTime']Expected order clause in the SQL query:
ORDER BY start_time ASCActual order clause in the SQL query:
ORDER BY create_time ASC, start_time ASCPossible Solution
Setting an
orderon the ApiResource should completely replace the default defined in api_platform.yaml. A default should not be forced onto every query, it should only provide a fallback in case no other, more specific value is chosen.Additional Context