【问题标题】:Api-platform order for childrenApi-平台儿童订单
【发布时间】:2019-04-27 17:12:49
【问题描述】:

我刚开始使用 api-platform 来获取一些实体及其所有子实体。 这里有一个self-join,SQL看起来像

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

我发现结果记录是按 id ORDER BY e0_.id ASC 排序的,而他们的孩子没有排序。

我的问题是如何排序他们的孩子也ORDER BY e0_.id ASC, e1_.id ASC

我查看了文档,似乎没有提及。 https://api-platform.com/docs/core/default-order

谢谢

【问题讨论】:

    标签: sorting children api-platform.com


    【解决方案1】:

    ORM 中的默认顺序:

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

    API平台默认顺序:

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

    API平台查询参数排序:

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

    【讨论】:

    • 非常感谢!有用!顺便说一句,另一种情况是只有当group=hierarchy这样的参数时才存在children,如果group=read,则没有children。有什么方法可以在 api 平台 yaml 文件中定义,例如 if group=hierarchy, then order: ['id'];如果 group=read,那么 order: ['id', 'related.id'] ?
    【解决方案2】:

    GonZOO 的答案在我的情况下不起作用,无法弄清楚为什么,所以我用 ORM 方式做了。我只是把它放在 one2many 关系 Doctrine docu 的注释中 请记住,它是硬编码的。

    【讨论】:

      猜你喜欢
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多