diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index ef27f2ed2..994d1519c 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -326,7 +326,16 @@ class SchemaTool foreach ($mapping->getJoinColumns() as $joinColumn) { $column = array(); $column['name'] = $mapping->getQuotedJoinColumnName($joinColumn['name'], $this->_platform); - $column['type'] = Type::getType($foreignClass->getTypeOfColumn($joinColumn['referencedColumnName'])); + $referencedColumnName = $joinColumn['referencedColumnName']; + $referencedFieldName = $foreignClass->getFieldName($referencedColumnName); + if (!$foreignClass->hasField($referencedFieldName)) { + throw new \Doctrine\Common\DoctrineException( + "Column name `$referencedColumnName` referenced for relation from ". + "$mapping->sourceEntityName towards $mapping->targetEntityName does not exist." + ); + } + $column['type'] = Type::getType($foreignClass->getTypeOfField($referencedFieldName)); + $columns[$column['name']] = $column; $constraint['local'][] = $column['name']; $constraint['foreign'][] = $joinColumn['referencedColumnName'];