Skip to content

Default order cannot be overwritten, only added to #8156

@carlobeltrame

Description

@carlobeltrame

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

  1. Have an ApiResource with at least two fields, e.g. a resource Event with two timestamps $createTime and $startTime
  2. In api_platform.yaml, set api_platform.defaults.order to the value createTime
  3. In the #[ApiResource()] annotation, add order: ['startTime']
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions