-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report
Q | A |
---|---|
BC Break | no |
Version | 2.11.1 |
PHP Version | 8.1.1 |
Summary
I have a entity with a read-only id property, and when a try to remove the entry a receive a LogicException. Attempting to change readonly property App\Entity\Supplier::$id.
Current behavior
The UnitOfWork always try to set the id of entity to null when it' executes the executeDeletions
method.
orm/lib/Doctrine/ORM/UnitOfWork.php
Lines 1254 to 1256 in ed50e3d
//$this->entityStates[$oid] = self::STATE_NEW; | |
if (! $class->isIdentifierNatural()) { | |
$class->reflFields[$class->identifier[0]]->setValue($entity, null); |
How to reproduce
#[ORM\Entity]
class Supplier
{
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
public readonly int $id;
public function __construct(
#[ORM\Column(nullable: false)]
public readonly string $name,
) {}
}
$entityManager->find(Supplier::class, 1);
$entityManager->remove($entity);
$entityManager->flush($entity);
Expected behavior
Delete the entry from database, but i dont know what's the expected behavior to the orm internals.
noemi-salaun, opalenet-adrien, ciekals11, Mirgen, bigfoot90 and 1 more
Metadata
Metadata
Assignees
Labels
No labels