diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php index 2e7d98950..e383fe9b1 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php @@ -269,6 +269,7 @@ private function addReferenceMapping(ClassMetadata $class, $reference, $type) $mapping = $attributes["@attributes"]; $mapping['strategy'] = isset($mapping['strategy']) ? strtolower($mapping['strategy']) : null; $mapping['targetDocument'] = isset($mapping['target-document']) ? $mapping['target-document'] : null; + $mapping['indexByNodeName'] = isset($mapping['index-by-nodename']) ? $mapping['index-by-nodename'] : null; unset($mapping['target-document']); if ($type === 'many') { diff --git a/lib/Doctrine/ODM/PHPCR/ReferenceManyCollection.php b/lib/Doctrine/ODM/PHPCR/ReferenceManyCollection.php index b2b00b964..b4497c589 100644 --- a/lib/Doctrine/ODM/PHPCR/ReferenceManyCollection.php +++ b/lib/Doctrine/ODM/PHPCR/ReferenceManyCollection.php @@ -100,13 +100,22 @@ public function initialize() $uow = $this->dm->getUnitOfWork(); $uow->getPrefetchHelper()->prefetch($this->dm, $referencedNodes, $this->locale); + $metadata = $this->dm->getClassMetadata(get_class($this->document)); + $metadata = $metadata->mappings[$this->property]; + $isAssociative = $metadata['index-by-nodename']; + $this->originalReferencePaths = array(); foreach ($referencedNodes as $referencedNode) { $proxy = $uow->getOrCreateProxyFromNode($referencedNode, $this->locale); if (isset($targetDocument) && !$proxy instanceof $this->targetDocument) { throw new PHPCRException("Unexpected class for referenced document at '{$referencedNode->getPath()}'. Expected '{$this->targetDocument}' but got '".ClassUtils::getClass($proxy)."'."); } - $referencedDocs[] = $proxy; + if ($isAssociative) { + $index = $referencedNode->getName(); + $referencedDocs[$index] = $proxy; + } else { + $referencedDocs[] = $proxy; + } $this->originalReferencePaths[] = $referencedNode->getPath(); }