Skip to content

Commit 97a7cb8

Browse files
committed
Unify JoinedSubclassPersister dequeue
Fix JoinedSubclassPersister as BasicEntityPersister was already fixed in GH-10735. The fix can be verified by modifying UnitOfWork to execute `BasicEntityPersister::executeInserts()` for multiple entities at once for the same entity class/persister instance - https://github.com/doctrine/orm/blob/2.20.3/src/UnitOfWork.php#L1186 - then reproducible on `Doctrine\Tests\ORM\Functional\Ticket\GH10531Test::testInserts` test. As extending/modifying UnitOfWork in tests in not easily possible, I submit this fix for v2.x without a test.
1 parent e005239 commit 97a7cb8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Persisters/Entity/BasicEntityPersister.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ public function executeInserts()
302302
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
303303
}
304304

305-
// Unset this queued insert, so that the prepareUpdateData() method knows right away
306-
// (for the next entity already) that the current entity has been written to the database
305+
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
306+
// knows right away (for the next entity already) that the current entity has been written to the database
307307
// and no extra updates need to be scheduled to refer to it.
308308
//
309309
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities

src/Persisters/Entity/JoinedSubclassPersister.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function executeInserts()
149149
// Execute all inserts. For each entity:
150150
// 1) Insert on root table
151151
// 2) Insert on sub tables
152-
foreach ($this->queuedInserts as $entity) {
152+
foreach ($this->queuedInserts as $key => $entity) {
153153
$insertData = $this->prepareInsertData($entity);
154154

155155
// Execute insert on root table
@@ -194,9 +194,16 @@ public function executeInserts()
194194
if ($this->class->requiresFetchAfterChange) {
195195
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
196196
}
197-
}
198197

199-
$this->queuedInserts = [];
198+
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
199+
// knows right away (for the next entity already) that the current entity has been written to the database
200+
// and no extra updates need to be scheduled to refer to it.
201+
//
202+
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
203+
// from its own list (\Doctrine\ORM\UnitOfWork::$entityInsertions) right after they
204+
// were given to our addInsert() method.
205+
unset($this->queuedInserts[$key]);
206+
}
200207
}
201208

202209
/**

0 commit comments

Comments
 (0)