Skip to content

Commit 7449571

Browse files
authored
Merge pull request #11934 from mvorisek/fix_joined_subclass_persister_insert_of_multiple_entities
Fix JoinedSubclassPersister when multiple entities are inserted
2 parents e005239 + 97a7cb8 commit 7449571

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)