Skip to content

Conflict between defaults.order and collection.order configs #4170

Description

@guilliamxavier

API Platform version(s) affected: 2.6.3

Description
The defaults.order config value, which would work as the global equivalent of https://api-platform.com/docs/core/default-order/#overriding-default-order (fields array), is also used in place of collection.order (direction string), which causes a TypeError.

How to reproduce
Config:

api_platform:
    defaults:
        order: [createdAt, id]

Error (on collection GET request):

Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\OrderExtension::__construct() must be of the type string or null, array given

Possible Solution
Revert the order-related changes of dc461fc (note that, unlike the collection.pagination.* non-*_parameter_name keys, collection.order is not deprecated, so I don't see the reason for wanting to move it to defaults.order, even more so since that key was already used after #3151)

Additional Context
Workaround for now: use the explicit attributes sublevel:

api_platform:
    defaults:
        attributes:
            order: [createdAt, id]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions