Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\PropertyAccessors\ReadonlyAccessor;
use Doctrine\ORM\Mapping\ToManyInverseSideMapping;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\ORM\Persisters\Collection\ManyToManyPersister;
Expand Down Expand Up @@ -1176,7 +1177,10 @@ private function executeDeletions(): void
// Entity with this $oid after deletion treated as NEW, even if the $oid
// is obtained by a new entity because the old one went out of scope.
//$this->entityStates[$oid] = self::STATE_NEW;
if (! $class->isIdentifierNatural()) {
if (
! $class->isIdentifierNatural() &&
! $class->propertyAccessors[$class->identifier[0]] instanceof ReadonlyAccessor
) {
$class->propertyAccessors[$class->identifier[0]]->setValue($entity, null);
}

Expand Down
41 changes: 41 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH9538Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH9538Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH9538EntityA::class,
]);
}

public function testCanRemoveEntityWithReadonlyId(): void
{
$this->_em->persist($entity = new GH9538EntityA());
$this->_em->flush();
$this->_em->remove($entity);
$this->_em->flush();
$this->expectNotToPerformAssertions();
}
}

#[Entity]
class GH9538EntityA
{
#[Column(type: 'integer')]
#[Id]
#[GeneratedValue(strategy: 'AUTO')]
public readonly int $id;
}
Loading