1
0
mirror of synced 2025-03-06 21:06:16 +03:00

#5935 #5684 #6020 #6152 extracted identifier conversion to a private method

This commit is contained in:
Marco Pivetta 2016-11-27 17:42:12 +01:00
parent 0a86c324ad
commit e736d19677

View File

@ -887,14 +887,7 @@ class UnitOfWork implements PropertyChangedListener
$idValue = $idGen->generate($this->em, $entity);
if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) {
$idField = $class->identifier[0];
$idValue = [
$idField => $this->em->getConnection()->convertToPHPValue(
$idValue,
$class->getTypeOfField($idField)
)
];
$idValue = [$class->getSingleIdentifierFieldName() => $this->convertSingleFieldIdentifierToPHPValue($class, $idValue)];
$class->setIdentifierValues($entity, $idValue);
}
@ -1012,11 +1005,8 @@ class UnitOfWork implements PropertyChangedListener
if ($postInsertIds) {
// Persister returned post-insert IDs
foreach ($postInsertIds as $postInsertId) {
$idField = $class->identifier[0];
$idValue = $this->em->getConnection()->convertToPHPValue(
$postInsertId['generatedId'],
$class->getTypeOfField($idField)
);
$idField = $class->getSingleIdentifierFieldName();
$idValue = $this->convertSingleFieldIdentifierToPHPValue($class, $postInsertId['generatedId']);
$entity = $postInsertId['entity'];
$oid = spl_object_hash($entity);
@ -3475,4 +3465,20 @@ class UnitOfWork implements PropertyChangedListener
}
}
}
/**
* @param ClassMetadata $class
* @param mixed $identifierValue
*
* @return mixed the identifier after type conversion
*
* @throws \Doctrine\ORM\Mapping\MappingException if the entity has more than a single identifier
*/
private function convertSingleFieldIdentifierToPHPValue(ClassMetadata $class, $identifierValue)
{
return $this->em->getConnection()->convertToPHPValue(
$identifierValue,
$class->getTypeOfField($class->getSingleIdentifierFieldName())
);
}
}