File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
tests/Tests/ORM/Functional Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -551,9 +551,11 @@ private function postCommitCleanup($entity): void
551551 private function computeScheduleInsertsChangeSets (): void
552552 {
553553 foreach ($ this ->entityInsertions as $ entity ) {
554- $ class = $ this ->em ->getClassMetadata (get_class ($ entity ));
555-
556- $ this ->computeChangeSet ($ class , $ entity );
554+ $ oid = spl_object_id ($ entity );
555+ if (!isset ($ this ->entityChangeSets [$ oid ])) {
556+ $ class = $ this ->em ->getClassMetadata (get_class ($ entity ));
557+ $ this ->computeChangeSet ($ class , $ entity );
558+ }
557559 }
558560 }
559561
@@ -929,6 +931,8 @@ public function computeChangeSets()
929931 }
930932 }
931933 }
934+
935+ $ this ->computeScheduleInsertsChangeSets ();
932936 }
933937
934938 /**
Original file line number Diff line number Diff line change @@ -40,6 +40,25 @@ public function testCallingPersistInPrePersistHook(): void
4040
4141 $ this ->assertTrue ($ this ->_em ->getUnitOfWork ()->isScheduledForInsert ($ entityWithCascade ));
4242 $ this ->assertTrue ($ this ->_em ->getUnitOfWork ()->isScheduledForInsert ($ entityWithUnmapped ));
43+
44+ $ this ->_em ->flush ();
45+ }
46+
47+ public function testPersistEntityOnFlushWithPrePersistHook (): void
48+ {
49+ $ this ->_em ->getEventManager ()->addEventListener (Events::prePersist, new PrePersistUnmappedPersistListener ());
50+
51+ $ alreadyPersistedEntity = new EntityWithCascadeAssociation ();
52+ $ this ->_em ->persist ($ alreadyPersistedEntity );
53+ $ this ->_em ->flush ();
54+
55+ $ entityWithUnmapped = new EntityWithUnmappedEntity ();
56+ $ entityWithCascade = new EntityWithCascadeAssociation ();
57+
58+ $ entityWithUnmapped ->unmapped = $ entityWithCascade ;
59+ $ alreadyPersistedEntity ->cascaded = $ entityWithUnmapped ;
60+
61+ $ this ->_em ->flush ();
4362 }
4463}
4564
You can’t perform that action at this time.
0 commit comments