Permalink
Browse files

Use IDs if available when registering embedded documents with UnitOfWork

If the identifier is not available, the SPL object hash is used. Previously, it was always used for embedded documents.
  • Loading branch information...
1 parent 7f73de3 commit cc422e43f957ba47466474535192074043c10f8e @jmikola jmikola committed Jan 14, 2014
@@ -321,7 +321,9 @@ private function generateHydratorClass(ClassMetadata $class, $hydratorClassName,
\$return = \$embeddedMetadata->newInstance();
\$embeddedData = \$this->dm->getHydratorFactory()->hydrate(\$return, \$embeddedDocument, \$hints);
- \$this->unitOfWork->registerManaged(\$return, null, \$embeddedData);
+ \$embeddedId = \$embeddedMetadata->identifier ? \$embeddedData[\$embeddedMetadata->identifier] : null;
+
+ \$this->unitOfWork->registerManaged(\$return, \$embeddedId, \$embeddedData);
\$this->unitOfWork->setParentAssociation(\$return, \$this->class->fieldMappings['%2\$s'], \$document, '%1\$s');
\$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
@@ -590,7 +590,9 @@ private function loadEmbedManyCollection(PersistentCollection $collection)
$embeddedDocumentObject = $embeddedMetadata->newInstance();
$data = $this->hydratorFactory->hydrate($embeddedDocumentObject, $embeddedDocument);
- $this->uow->registerManaged($embeddedDocumentObject, null, $data);
+ $id = $embeddedMetadata->identifier ? $data[$embeddedMetadata->identifier] : null;
+
+ $this->uow->registerManaged($embeddedDocumentObject, $id, $data);
$this->uow->setParentAssociation($embeddedDocumentObject, $mapping, $owner, $mapping['name'] . '.' . $key);
if ($mapping['strategy'] === 'set') {
$collection->set($key, $embeddedDocumentObject);

0 comments on commit cc422e4

Please sign in to comment.