Search code examples
sortingchildrenapi-platform.com

Api-platform order for children


I just begin to use api-platform to GET some entities and all their children. There is a self-join here, SQL looks like

entity e0_
        LEFT JOIN
    entity e1_ ON e0_.id = e1_.parent_id

I found the result records are sorted by id ORDER BY e0_.id ASC, while their children are not sorted.

My question is how to sort their children also ORDER BY e0_.id ASC, e1_.id ASC

I viewed the document, seems not mentioned. https://api-platform.com/docs/core/default-order

thanks


Solution

  • Default order in ORM:

    https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/ordered-associations.html

    Default order in API platform:

     * @ApiResource(attributes={"order"={"related.id": "ASC"}})
    

    Order by query param in API platform:

    https://api-platform.com/docs/core/filters/#filtering-on-nested-properties