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
11 changes: 8 additions & 3 deletions src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ private function postCommitCleanup($entity): void
private function computeScheduleInsertsChangeSets(): void
{
foreach ($this->entityInsertions as $entity) {
$class = $this->em->getClassMetadata(get_class($entity));

$this->computeChangeSet($class, $entity);
$oid = spl_object_id($entity);
if (! isset($this->entityChangeSets[$oid])) {
$class = $this->em->getClassMetadata(get_class($entity));
$this->computeChangeSet($class, $entity);
}
}
}

Expand Down Expand Up @@ -929,6 +931,9 @@ public function computeChangeSets()
}
}
}

// Check again for uncomputed changes that might be added by hooks
$this->computeScheduleInsertsChangeSets();
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/Tests/ORM/Functional/PrePersistEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ public function testCallingPersistInPrePersistHook(): void

$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithCascade));
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithUnmapped));

$this->_em->flush();
}

public function testPersistEntityOnFlushWithPrePersistHook(): void
{
$this->_em->getEventManager()->addEventListener(Events::prePersist, new PrePersistUnmappedPersistListener());

$alreadyPersistedEntity = new EntityWithCascadeAssociation();
$this->_em->persist($alreadyPersistedEntity);
$this->_em->flush();

$entityWithUnmapped = new EntityWithUnmappedEntity();
$entityWithCascade = new EntityWithCascadeAssociation();

$entityWithUnmapped->unmapped = $entityWithCascade;
$alreadyPersistedEntity->cascaded = $entityWithUnmapped;

$this->_em->flush();

$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($entityWithCascade));
}
}

Expand Down