【问题标题】:Api-platform: how to output related entity id instead of resource path?Api-platform:如何输出相关实体id而不是资源路径?
【发布时间】:2018-07-18 07:09:12
【问题描述】:

如何获取相关实体 ID 而不是资源路径?

例如,这是我现在得到的:

{
  "id": "/api/articles/0d8cb40c-221b-4c54-9e29-43877093b839",
  "type": "Article",
  "attributes": {
    "_id": "0d8cb40c-221b-4c54-9e29-43877093b839",
    "title": "Article",
    "content": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
    "dateCreated": "2018-07-17T18:20:29+03:00",
    "dateUpdated": "2018-07-17T18:20:29+03:00"
  },
  "relationships": {
    "author": {
      "data": {
        "type": "User",
        "id": "/api/users/b26e0381-6800-4f47-b269-9a92b27ad331"
      }
    }
  }
}

我想得到这样的相关实体ID:

"relationships": {
"author": {
  "data": {
    "type": "User",
    "id": "b26e0381-6800-4f47-b269-9a92b27ad331"
  }
}

【问题讨论】:

    标签: api-platform.com


    【解决方案1】:

    您可以使用以下配置:

    api_platform:
        allow_plain_identifiers: true
    

    但请注意:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      相关资源
      最近更新 更多