Limit foreign key creation current connector
Updated fk generation to make sure that it doesn't try to create foreign keys linking to another DB/connector
This commit is contained in:
parent
4d20fa7746
commit
d461d07f34
|
@ -418,15 +418,19 @@ function mixinMigration(MySQL, mysql) {
|
||||||
//TODO validate that these are in the same DB, etc.
|
//TODO validate that these are in the same DB, etc.
|
||||||
//TODO this is probably a better place to check this than in autoupdate or buildColumnDefinitions
|
//TODO this is probably a better place to check this than in autoupdate or buildColumnDefinitions
|
||||||
var definition = this.getModelDefinition(model);
|
var definition = this.getModelDefinition(model);
|
||||||
|
|
||||||
var fk = definition.settings.foreignKeys[keyName];
|
var fk = definition.settings.foreignKeys[keyName];
|
||||||
if (fk) {
|
if (fk) {
|
||||||
var fkEntity = typeof fk.entity === 'object' ? fk.entity : {name: fk.entity}; //this.getModelDefinition(fk.entity);
|
//get the definition of the referenced object
|
||||||
|
var fkEntityName = (typeof fk.entity === 'object') ? fk.entity.name : fk.entity;
|
||||||
|
|
||||||
//TODO verify that the other model in the same DB
|
//verify that the other model in the same DB
|
||||||
return ' CONSTRAINT ' + this.client.escapeId(fk.name) +
|
if (this._models[fkEntityName]) {
|
||||||
' FOREIGN KEY (' + fk.foreignKey + ')' +
|
return ' CONSTRAINT ' + this.client.escapeId(fk.name) +
|
||||||
' REFERENCES ' + this.tableEscaped(fkEntity.name) +
|
' FOREIGN KEY (' + fk.foreignKey + ')' +
|
||||||
'(' + this.client.escapeId(fk.entityKey) + ')';
|
' REFERENCES ' + this.tableEscaped(fkEntityName) +
|
||||||
|
'(' + this.client.escapeId(fk.entityKey) + ')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue