diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 74c5afc1d93..826933fbf5e 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -423,12 +423,34 @@ public function commit($entity = null) $this->entityUpdates = $this->entityDeletions = $this->extraUpdates = - $this->entityChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = - $this->scheduledForSynchronization = $this->orphanRemovals = array(); + + if ($entity === null) { + $this->entityChangeSets = $this->scheduledForSynchronization = array(); + } elseif (is_object($entity)) { + $oid = spl_object_hash($entity); + $class = $this->em->getClassMetadata(get_class($entity)); + if (isset($this->entityChangeSets[$oid])) { + unset($this->entityChangeSets[$oid]); + } + if (isset($this->scheduledForSynchronization[$class->rootEntityName][$oid])) { + unset($this->scheduledForSynchronization[$class->rootEntityName][$oid]); + } + } elseif (is_array($entity)) { + foreach ($entity as $object) { + $oid = spl_object_hash($object); + $class = $this->em->getClassMetadata(get_class($object)); + if (isset($this->entityChangeSets[$oid])) { + unset($this->entityChangeSets[$oid]); + } + if (isset($this->scheduledForSynchronization[$class->rootEntityName][$oid])) { + unset($this->scheduledForSynchronization[$class->rootEntityName][$oid]); + } + } + } } /**