Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading references if mapped by uuid and not by id. #36

Merged
Merged
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
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