Commit 49d2dd9b authored by beberlei's avatar beberlei

[2.0] DDC-329 - Allow Reverse Engineering with multiple column foreign keys

parent 5a96217d
......@@ -124,30 +124,21 @@ class DatabaseDriver implements Driver
}
foreach ($foreignKeys as $foreignKey) {
if (count($foreignKey->getColumns()) != 1) {
throw new MappingException(
"Cannot generate mapping for table '".$tableName."' with foreign keys with multiple local columns."
);
}
$cols = $foreignKey->getColumns();
$localColumn = current($cols);
$fkCols = $foreignKey->getForeignColumns();
if (count($fkCols) != 1) {
throw new MappingException(
"Cannot generate mapping for table '".$tableName."' with foreign keys with multiple foreign columns."
);
}
$foreignColumn = current($fkCols);
$associationMapping = array();
$associationMapping['fieldName'] = Inflector::camelize(str_ireplace('_id', '', $localColumn));
$associationMapping['columnName'] = $localColumn;
$associationMapping['targetEntity'] = Inflector::classify($foreignKey->getForeignTableName());
$associationMapping['joinColumns'][] = array(
'name' => $localColumn,
'referencedColumnName' => $foreignColumn
);
for ($i = 0; $i < count($cols); $i++) {
$associationMapping['joinColumns'][] = array(
'name' => $cols[$i],
'referencedColumnName' => $fkCols[$i],
);
}
$metadata->mapManyToOne($associationMapping);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment