#1267 - DDL issue on @OneToMany @JoinTable ... extra unnecessary index created on fk column

This commit is contained in:
Rob Bygrave
2018-02-22 22:09:53 +13:00
parent 83384c6f0e
commit 4d122ea05b
2 changed files with 9 additions and 0 deletions
@@ -656,4 +656,12 @@ public class MTable {
return draftTableName + "." + references.substring(lastDot + 1);
}
/**
* Clear the indexes on the foreign keys as they are covered by unique constraints.
*/
public void clearForeignKeyIndexes() {
for (MCompoundForeignKey compoundKey : compoundKeys) {
compoundKey.setIndexName(null);
}
}
}
@@ -133,6 +133,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
// in the middle of rendering the create table DDL
MTable intersectionTable = new ModelBuildIntersectionTable(ctx, p).build();
if (p.isO2mJoinTable()) {
intersectionTable.clearForeignKeyIndexes();
Collection<MColumn> cols = intersectionTable.allColumns();
if (cols.size() == 2) {
// always the second column that we put the unique constraint on