1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Use identifier flattener to retrevie entity identifiers

This commit is contained in:
Asmir Mustafic 2015-02-11 17:04:24 +01:00
parent 58e20c70c6
commit a2461d6d5f

View file

@ -25,6 +25,7 @@ use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Utility\IdentifierFlattener;
/** /**
* Default hydrator cache for entities * Default hydrator cache for entities
@ -44,6 +45,13 @@ class DefaultEntityHydrator implements EntityHydrator
*/ */
private $uow; private $uow;
/**
* The IdentifierFlattener used for manipulating identifiers
*
* @var \Doctrine\ORM\Utility\IdentifierFlattener
*/
private $identifierFlattener;
/** /**
* @var array * @var array
*/ */
@ -56,6 +64,7 @@ class DefaultEntityHydrator implements EntityHydrator
{ {
$this->em = $em; $this->em = $em;
$this->uow = $em->getUnitOfWork(); $this->uow = $em->getUnitOfWork();
$this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory());
} }
/** /**
@ -73,14 +82,13 @@ class DefaultEntityHydrator implements EntityHydrator
} }
if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) { if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) {
$associatedEntity = $data[$name]; $targetClassMetadata = $this->em->getClassMetadata($assoc['targetEntity']);
$associationIds = $this->identifierFlattener->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($data[$name]));
unset($data[$name]); unset($data[$name]);
if ($this->uow->isInIdentityMap($associatedEntity)) { foreach ($associationIds as $fieldName => $fieldValue) {
$targetEntityMetadata = $this->em->getClassMetadata($assoc['targetEntity']); $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->getColumnName($fieldName)]] = $fieldValue;
foreach ($this->uow->getEntityIdentifier($associatedEntity) as $fieldName => $fieldValue) {
$data[$assoc['targetToSourceKeyColumns'][$targetEntityMetadata->getColumnName($fieldName)]] = $fieldValue;
}
} }
continue; continue;
} }