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 ...@@ -124,30 +124,21 @@ class DatabaseDriver implements Driver
} }
foreach ($foreignKeys as $foreignKey) { 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(); $cols = $foreignKey->getColumns();
$localColumn = current($cols); $localColumn = current($cols);
$fkCols = $foreignKey->getForeignColumns(); $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 = array();
$associationMapping['fieldName'] = Inflector::camelize(str_ireplace('_id', '', $localColumn)); $associationMapping['fieldName'] = Inflector::camelize(str_ireplace('_id', '', $localColumn));
$associationMapping['columnName'] = $localColumn;
$associationMapping['targetEntity'] = Inflector::classify($foreignKey->getForeignTableName()); $associationMapping['targetEntity'] = Inflector::classify($foreignKey->getForeignTableName());
$associationMapping['joinColumns'][] = array(
'name' => $localColumn, for ($i = 0; $i < count($cols); $i++) {
'referencedColumnName' => $foreignColumn $associationMapping['joinColumns'][] = array(
); 'name' => $cols[$i],
'referencedColumnName' => $fkCols[$i],
);
}
$metadata->mapManyToOne($associationMapping); $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