api-platform / api-platform/core

Unable to create an entity by passing a Uuid as a call from the client

未關閉
#8,129 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
doctrine Serializer State
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

**API Platform version(s) affected**: 3.4.0
**Symfony version(s) affected**: 6.4.10

**Description**
I am building a CQRS system based on symfony + apiplatform + ecotone.
My goal is to create a new entity with an ID passed by the client

When I try I get the error: "Update is not allowed for this operation."

If I enable "api_allow_update", I have to create a custom provider for GET, to retrieve Entity.

**How to reproduce**

Sample POST call
```
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"hostname": "string"
}
```

My Entity:
``` Tenant
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[Groups("registration")]
#[ApiProperty(writable: true, identifier: true, types: ['https://schema.org/identifier'])]
protected Uuid $id;
...
...
```

**Possible Solution**

**Additional Context**

POST(denormalizationContext: ['api_allow_update' => false, 'groups' => ['registration']],)
![image](https://github.com/user-attachments/assets/6bd8075b-1a87-438e-a136-fe61582a349b)

POST(denormalizationContext: ['api_allow_update' => true, 'groups' => ['registration']],)
![image](https://github.com/user-attachments/assets/424ad6a9-5a01-464c-bc1b-501f25fca96c)

GET(provider: TenantProvider::class,)
Here I have to find an entity, with the Id!
```
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Tenant|null
{
print_r($uriVariables); die;
```
![image](https://github.com/user-attachments/assets/5c23c1ec-f64f-483a-9df5-3348b5db5e25)

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。