1
0
mirror of synced 2025-01-19 06:51:40 +03:00

#1178 - PersisterHelper::getTypeOfColumn() should not fail silently, as that makes persister bugs impossible to spot

This commit is contained in:
Marco Pivetta 2015-01-17 02:45:50 +01:00
parent a80532a538
commit aaa6443954

View File

@ -107,7 +107,9 @@ class PersisterHelper
* @param ClassMetadata $class * @param ClassMetadata $class
* @param EntityManagerInterface $em * @param EntityManagerInterface $em
* *
* @return string|null * @return string
*
* @throws \RuntimeException
*/ */
public static function getTypeOfColumn($columnName, ClassMetadata $class, EntityManagerInterface $em) public static function getTypeOfColumn($columnName, ClassMetadata $class, EntityManagerInterface $em)
{ {
@ -117,10 +119,9 @@ class PersisterHelper
if (isset($class->fieldMappings[$fieldName])) { if (isset($class->fieldMappings[$fieldName])) {
return $class->fieldMappings[$fieldName]['type']; return $class->fieldMappings[$fieldName]['type'];
} }
return null;
} }
// iterate over to-one association mappings
foreach ($class->associationMappings as $assoc) { foreach ($class->associationMappings as $assoc) {
if ( ! isset($assoc['joinColumns'])) { if ( ! isset($assoc['joinColumns'])) {
continue; continue;
@ -136,6 +137,26 @@ class PersisterHelper
} }
} }
return null; // iterate over to-many association mappings
foreach ($class->associationMappings as $assoc) {
if ( ! (isset($assoc['joinTable']) && isset($assoc['joinTable']['joinColumns']))) {
continue;
}
foreach ($assoc['joinTable']['joinColumns'] as $joinColumn) {
if ($joinColumn['name'] == $columnName) {
$targetColumnName = $joinColumn['referencedColumnName'];
$targetClass = $em->getClassMetadata($assoc['targetEntity']);
return self::getTypeOfColumn($targetColumnName, $targetClass, $em);
}
}
}
throw new \RuntimeException(sprintf(
'Could not resolve type of column "%s" of class "%s"',
$columnName,
$class->getName()
));
} }
} }