Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
11 changes: 10 additions & 1 deletion lib/Doctrine/ODM/PHPCR/ReferenceManyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might overwrite other referenced documents with the same node name. we should use $referenceNode->getPath() i think.

} else {
$referencedDocs[] = $proxy;
}
$this->originalReferencePaths[] = $referencedNode->getPath();
}

Expand Down