api-platform / api-platform/core
Entity with two unique fields cannot be PUT (duplicate entry exception)
- 主要語言
- PHP
- 星號
- 2.6k
- 分支
- 980
- 平均合併
- 2 天 5 小時
- 30 天內合併 PR
- 48
描述
**API Platform version(s) affected**: 3.1.1
**Description**
An Entity with two combined properties being unique together cannot be PUT, as a child inside the parent Entity. When trying to PUT the parent Entity (`Customer`) with the child Entity (`CustomerTask`) that has the 2 unique fields (`$task` + `$customer`), the API tells that the Entity `CustomerTask` does already exist, though should actually replace it.
Error Message:
> An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '\\x01\\x86\\x7F~X?r\\xA8\\xA4\\xC' for key 'unique_customer_task'
**How to reproduce**
This is how the entity looks:
```php
#[ORM\Entity(repositoryClass: CustomerTaskRepository::class)]
#[ORM\UniqueConstraint(name: 'unique_customer_task', fields: ['task', 'customer'])]
#[UniqueEntity(fields: ['task', 'customer'], message: 'Task already exist for customer')]
class CustomerTask
{
#[ORM\Id]
#[ORM\Column(type: "uuid", unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")]
private ?Uuid $id = null;
// Affected Unique Properties:
#[ORM\ManyToOne(inversedBy: 'customerTasks')]
#[ORM\JoinColumn(nullable: false)]
private ?Task $task = null;
#[ORM\ManyToOne(inversedBy: 'customerTasks')]
#[ORM\JoinColumn(nullable: false)]
private ?Customer $customer = null;
/....
}
```
**Possible Solution**
**Additional Context**
Is there a known issue with multiple unique fields? Or am I doing sth wrong?
貢獻指南
評估
這個 Issue 還沒有評估資料。