From b98280a504e1190479777e5f1d3a17429e8c04c3 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Wed, 18 Jan 2012 23:09:23 -0500 Subject: [PATCH] Quick optimizations are always good. --- lib/Doctrine/ORM/UnitOfWork.php | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 49b3fcd34..09ba8004a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -705,15 +705,17 @@ class UnitOfWork implements PropertyChangedListener foreach ($unwrappedValue as $key => $entry) { $state = $this->getEntityState($entry, self::STATE_NEW); - $oid = spl_object_hash($entry); - if (!($entry instanceof $assoc['targetEntity'])) { - throw new ORMException(sprintf("Found entity of type %s on association %s#%s, but expecting %s", - get_class($entry), - $assoc['sourceEntity'], - $assoc['fieldName'], - $targetClass->name - )); + if ( ! ($entry instanceof $assoc['targetEntity'])) { + throw new ORMException( + sprintf( + 'Found entity of type %s on association %s#%s, but expecting %s', + get_class($entry), + $assoc['sourceEntity'], + $assoc['fieldName'], + $targetClass->name + ) + ); } switch ($state) { @@ -1010,7 +1012,7 @@ class UnitOfWork implements PropertyChangedListener // are not yet available. $newNodes = array(); - foreach ($entityChangeSet as $oid => $entity) { + foreach ($entityChangeSet as $entity) { $className = get_class($entity); if ($calc->hasClass($className)) { @@ -1656,7 +1658,8 @@ class UnitOfWork implements PropertyChangedListener foreach ($id as $idField => $idValue) { if (isset($class->associationMappings[$idField])) { $targetClassMetadata = $this->em->getClassMetadata($class->associationMappings[$idField]['targetEntity']); - $associatedId = $this->getEntityIdentifier($idValue); + $associatedId = $this->getEntityIdentifier($idValue); + $flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]]; } } @@ -2418,9 +2421,9 @@ class UnitOfWork implements PropertyChangedListener case (isset($this->identityMap[$targetClass->rootEntityName][$relatedIdHash])): $newValue = $this->identityMap[$targetClass->rootEntityName][$relatedIdHash]; - // if this is an uninitialized proxy, we are deferring eager loads, + // If this is an uninitialized proxy, we are deferring eager loads, // this association is marked as eager fetch, and its an uninitialized proxy (wtf!) - // then we cann append this entity for eager loading! + // then we can append this entity for eager loading! if ($hints['fetchMode'][$class->name][$field] == ClassMetadata::FETCH_EAGER && isset($hints['deferEagerLoad']) && !$targetClass->isIdentifierComposite && @@ -2515,13 +2518,13 @@ class UnitOfWork implements PropertyChangedListener $this->eagerLoadingEntities = array(); foreach ($eagerLoadingEntities as $entityName => $ids) { + if ( ! $ids) continue; + $class = $this->em->getClassMetadata($entityName); - if ($ids) { - $this->getEntityPersister($entityName)->loadAll( - array_combine($class->identifier, array(array_values($ids))) - ); - } + $this->getEntityPersister($entityName)->loadAll( + array_combine($class->identifier, array(array_values($ids))) + ); } } @@ -2901,7 +2904,7 @@ class UnitOfWork implements PropertyChangedListener */ public function isReadOnly($object) { - if ( ! is_object($object) ) { + if ( ! is_object($object)) { throw ORMInvalidArgumentException::readOnlyRequiresManagedEntity($object); }