Skip to content

Commit

Permalink
[ResourceBundle] EntityMerger, check if entity is already loaded by UoW
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Apr 27, 2024
1 parent e9b9498 commit a1c4998
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/CoreShop/Bundle/ResourceBundle/Doctrine/ORM/EntityMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ private function doMerge($entity, array &$visited): void
}

$visited[$oid] = $entity; // mark visited
$class = $this->em->getClassMetadata($entity::class);

if ($entity instanceof Proxy && !$entity->__isInitialized()) {
$entity->__load();
$id = $class->getIdentifierValues($entity);

$uwEntity = $this->em->getUnitOfWork()->tryGetById($id, $class->getName());

if ($uwEntity) {
$entity = $uwEntity;
}
else {
$entity->__load();
}
}

$class = $this->em->getClassMetadata($entity::class);

if ($this->em->getUnitOfWork()->getEntityState($entity, UnitOfWork::STATE_DETACHED) !== UnitOfWork::STATE_MANAGED) {
$id = $class->getIdentifierValues($entity);
Expand Down

0 comments on commit a1c4998

Please sign in to comment.