File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
tests/Tests/ORM/Functional/Ticket Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 3535use Doctrine \ORM \Mapping \AssociationMapping ;
3636use Doctrine \ORM \Mapping \ClassMetadata ;
3737use Doctrine \ORM \Mapping \MappingException ;
38+ use Doctrine \ORM \Mapping \PropertyAccessors \ReadonlyAccessor ;
3839use Doctrine \ORM \Mapping \ToManyInverseSideMapping ;
3940use Doctrine \ORM \Persisters \Collection \CollectionPersister ;
4041use Doctrine \ORM \Persisters \Collection \ManyToManyPersister ;
@@ -1176,7 +1177,11 @@ private function executeDeletions(): void
11761177 // Entity with this $oid after deletion treated as NEW, even if the $oid
11771178 // is obtained by a new entity because the old one went out of scope.
11781179 //$this->entityStates[$oid] = self::STATE_NEW;
1179- if (! $ class ->isIdentifierNatural ()) {
1180+ if (
1181+ ! $ class ->isIdentifierNatural () && ! (
1182+ $ class ->propertyAccessors [$ class ->identifier [0 ]] instanceof ReadonlyAccessor &&
1183+ $ class ->propertyAccessors [$ class ->identifier [0 ]]->getUnderlyingReflector ()->isInitialized ($ entity ))
1184+ ) {
11801185 $ class ->propertyAccessors [$ class ->identifier [0 ]]->setValue ($ entity , null );
11811186 }
11821187
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Doctrine \Tests \ORM \Functional \Ticket ;
6+
7+ use Doctrine \ORM \Mapping \Column ;
8+ use Doctrine \ORM \Mapping \Entity ;
9+ use Doctrine \ORM \Mapping \GeneratedValue ;
10+ use Doctrine \ORM \Mapping \Id ;
11+ use Doctrine \Tests \OrmFunctionalTestCase ;
12+
13+ class GH9538Test extends OrmFunctionalTestCase
14+ {
15+ protected function setUp (): void
16+ {
17+ parent ::setUp ();
18+
19+ $ this ->setUpEntitySchema ([
20+ GH9538EntityA::class,
21+ ]);
22+ }
23+
24+ public function testCanRemoveEntityWithReadonlyId (): void
25+ {
26+ $ this ->_em ->persist ($ entity = new GH9538EntityA ());
27+ $ this ->_em ->flush ();
28+ $ this ->_em ->remove ($ entity );
29+ $ this ->_em ->flush ();
30+ $ this ->expectNotToPerformAssertions ();
31+ }
32+ }
33+
34+ #[Entity]
35+ class GH9538EntityA
36+ {
37+ #[Column(type: 'integer ' )]
38+ #[Id]
39+ #[GeneratedValue(strategy: 'AUTO ' )]
40+ public readonly int $ id ;
41+ }
You can’t perform that action at this time.
0 commit comments