API 平台 - 允许在 PUT 中创建子资源

问题描述 投票:0回答:0

我很确定这在其他地方之前是有效的,但我现在无法让它工作。 我也很确定这是因为 PUT 请求。 我可以使用一个选项来允许在 PUT 请求中创建子资源吗? 我已经在两个实体中尝试过

new Put(allowCreate: true)
顺便说一句:可以编辑子资源!

API 平台 3.1.4 交响乐:6.2.7

Mainressource => 实体事件:

{
  "@context": "string",
  "@id": "string",
  "@type": "string",
  "id": 0,
  "maxParticipants": 0,
  "qualification": {
    "@context": "string",
    "@id": "string",
    "@type": "string",
    "topicNumber": "string",
    "title": "string"
  },
  "eventDate": "2023-03-17T10:11:56.845Z",
  "participants": [
    {
      "@context": "string",
      "@id": "string",
      "@type": "string",
      "id": 0,
      "event": "string",
      "passed": true,
      "appeared": true,
      "participant": {
        "@context": "string",
        "@id": "string",
        "@type": "string",
        "id": 0,
        "firstName": "string",
        "lastName": "string"
      }
    }
  ]
}

当我进行 PUT 时,我希望 API 平台创建一个添加参与者:

{
    "@id": "/api/events/1",
    "@type": "Event",
    "id": 1,
    "maxParticipants": 22,
    "qualification": {
        "@id": "/api/qualifications/2",
        "@context": null,
        "@type": "Qualification",
        "id": null,
        "topicNumber": "12",
        "title": "Test 1",
        "validityInYears": 0,
        "approved": false,
        "extendable": false
    },
    "eventDate": "2023-01-13T00:00:00+01:00",
    "participants": [
        {
            "@id": "/api/event_participants/1",
            "@context": null,
            "@type": "EventParticipant",
            "id": null,
            "participant": "/api/users/2",
            "event": "/api/events/1",
            "appeared": false,
            "passed": false
        },
        {
            "@id": null,
            "@context": null,
            "@type": "EventParticipant",
            "id": null,
            "participant": "/api/users/71",
            "event": "/api/events/1",
            "appeared": false,
            "passed": false
        }
    ]
}

我检查一切:

  • SerializationGroups 是正确的
  • 级联持久化设置
  • addParticipant 函数在 Event::class 中实现
symfony api-platform.com
© www.soinside.com 2019 - 2024. All rights reserved.