From 4826739824fa10827fc9ddb0d3ef3ea9a83f49de Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Mon, 9 Aug 2010 21:44:52 +0200 Subject: [PATCH] Simplified ClassMetadata lookup in UnitOfWork and added docblock. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 16 ---------------- lib/Doctrine/ORM/UnitOfWork.php | 16 +++++++++++----- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index c25835bb7..c2bcab1f4 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1172,22 +1172,6 @@ class ClassMetadataInfo $type == self::INHERITANCE_TYPE_TABLE_PER_CLASS; } - /** - * Makes some automatic additions to the association mapping to make the life - * easier for the user, and store join columns in the metadata. - * - * @param array $mapping - * @todo Pass param by ref? - */ - /*private function _completeAssociationMapping(array $mapping) - { - $mapping['sourceEntity'] = $this->name; - if (isset($mapping['targetEntity']) && strpos($mapping['targetEntity'], '\\') === false && strlen($this->namespace) > 0) { - $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity']; - } - return $mapping; - }*/ - /** * Adds a mapped field to the class. * diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f3da91002..3700ac056 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -389,7 +389,7 @@ class UnitOfWork implements PropertyChangedListener * @param ClassMetadata $class The class descriptor of the entity. * @param object $entity The entity for which to compute the changes. */ - public function computeChangeSet(Mapping\ClassMetadata $class, $entity) + public function computeChangeSet(ClassMetadata $class, $entity) { if ( ! $class->isInheritanceTypeNone()) { $class = $this->em->getClassMetadata(get_class($entity)); @@ -1901,11 +1901,10 @@ class UnitOfWork implements PropertyChangedListener } else { if ($targetClass->subClasses) { // If it might be a subtype, it can not be lazy - //$newValue = $assoc->load($entity, null, $this->em, $associatedId); $newValue = $this->getEntityPersister($assoc['targetEntity']) ->loadOneToOneEntity($assoc, $entity, null, $associatedId); } else { - if ($assoc['fetch'] == Mapping\ClassMetadata::FETCH_EAGER) { + if ($assoc['fetch'] == ClassMetadata::FETCH_EAGER) { // TODO: Maybe it could be optimized to do an eager fetch with a JOIN inside // the persister instead of this rather unperformant approach. $newValue = $this->em->find($assoc['targetEntity'], $associatedId); @@ -1938,10 +1937,9 @@ class UnitOfWork implements PropertyChangedListener ); $pColl->setOwner($entity, $assoc); $reflField->setValue($entity, $pColl); - if ($assoc['fetch'] == Mapping\ClassMetadata::FETCH_LAZY) { + if ($assoc['fetch'] == ClassMetadata::FETCH_LAZY) { $pColl->setInitialized(false); } else { - //$assoc->load($entity, $pColl, $this->em); $this->loadCollection($assoc, $entity, $pColl); } $this->originalEntityData[$oid][$field] = $pColl; @@ -1961,6 +1959,14 @@ class UnitOfWork implements PropertyChangedListener return $entity; } + /** + * Initializes (loads) an associated collection of an entity. + * + * @param array $assoc The association mapping. + * @param object $sourceEntity The entity that "owns" the collection. + * @param PeristentCollection $targetCollection The collection to initialize. + * @todo Maybe later move to EntityManager#initialize($proxyOrCollection). See DDC-733. + */ public function loadCollection(array $assoc, $sourceEntity, $targetCollection) { switch ($assoc['type']) {