From e018bb83f0d2c0e92560c4644ec9f4d008cb741b Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 4 Nov 2013 12:42:23 +0100 Subject: [PATCH] [DDC-2775] Bugfix --- lib/Doctrine/ORM/UnitOfWork.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 5de769f63..8b449bdb4 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2230,6 +2230,10 @@ class UnitOfWork implements PropertyChangedListener function ($assoc) { return $assoc['isCascadeRemove']; } ); + $entitiesToCascade = array(); + + // We need to load all related entities beforehand so that lazy collection loading doesn't + // reload entities after they have been removed (bug DDC-2775) foreach ($associationMappings as $assoc) { if ($entity instanceof Proxy && !$entity->__isInitialized__) { $entity->__load(); @@ -2242,18 +2246,22 @@ class UnitOfWork implements PropertyChangedListener case (is_array($relatedEntities)): // If its a PersistentCollection initialization is intended! No unwrap! foreach ($relatedEntities as $relatedEntity) { - $this->doRemove($relatedEntity, $visited); + $entitiesToCascade[] = $relatedEntity; } break; case ($relatedEntities !== null): - $this->doRemove($relatedEntities, $visited); + $entitiesToCascade[] = $relatedEntities; break; default: // Do nothing } } + + foreach ($entitiesToCascade as $relatedEntity) { + $this->doRemove($relatedEntity, $visited); + } } /**