Skip to content

Commit

Permalink
Merge pull request #36 from joschi127/load-reference-by-uuid-fix
Browse files Browse the repository at this point in the history
Fix loading references if mapped by uuid and not by id.
  • Loading branch information
ElectricMaxxx committed Feb 6, 2016
2 parents c01aa38 + bac6f73 commit b41ff53
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/Doctrine/ORM/ODMAdapter/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Doctrine\ORM\ODMAdapter\Event\ManagerEventArgs;
use Doctrine\ORM\ODMAdapter\Exception\UnitOfWorkException;
use Doctrine\ORM\ODMAdapter\Mapping\ClassMetadata;
use PHPCR\ItemNotFoundException;
use PHPCR\Util\UUIDHelper;

/**
* Unit of work class
Expand Down Expand Up @@ -472,6 +474,24 @@ public function loadReferences($object)
continue;
}

if (UUIDHelper::isUUID($objectValue)) {
// DocumentManager::getReference() does not work correctly if called with an uuid instead of an id,
// so if we have an uuid here, we have to fetch the node first (which unfortunately is not optimal
// from a performance point of view) to get the correct id of the document.
// (DocumentManager::getReference() seems to work first - but it will initialize the id field with the
// uuid and this will cause errors later, e.g. when accessing other referenced documents of the loaded
// document - it is simply not possible to use it correctly with an uuid)
try {
$referencedNode = $this->objectAdapterManager
->getManager($object, $fieldName)
->getPhpcrSession()
->getNodeByIdentifier($objectValue);

$objectValue = $referencedNode->getPath();
} catch (ItemNotFoundException $e) {
continue;
}
}

$referencedObject = $this->objectAdapterManager
->getManager($object, $fieldName)
Expand Down

0 comments on commit b41ff53

Please sign in to comment.