Hi,
I'm using loopback with MySQL and I've noted that's impossible to add the constraint "ON DELETE" and "ON UPDATE" to your foreign keys.
I've looked in code and I've found this function
`MySQL.prototype.buildForeignKeyDefinition = function(model, keyName) {
var definition = this.getModelDefinition(model);
var fk = definition.settings.foreignKeys[keyName];
if (fk) {
// get the definition of the referenced object
var fkEntityName = (typeof fk.entity === 'object') ? fk.entity.name : fk.entity;
// verify that the other model in the same DB
if (this._models[fkEntityName]) {
return ' CONSTRAINT ' + this.client.escapeId(fk.name) +
' FOREIGN KEY (`' + expectedColNameForModel(fk.foreignKey, definition) + '`)' +
' REFERENCES ' + this.tableEscaped(fkEntityName) +
'(' + this.client.escapeId(fk.entityKey) + ')';
}
}
return '';
};`
As you can see the constraints is absent in SQL code generation. This is annoying if you use the autoupdate.
For the moment I removed the foreign keys from model definitions and added them manually manually using alter table statements.
Can you add this missing feature please!
Thanks!
Francesco
Hi,
I'm using loopback with MySQL and I've noted that's impossible to add the constraint "ON DELETE" and "ON UPDATE" to your foreign keys.
I've looked in code and I've found this function
`MySQL.prototype.buildForeignKeyDefinition = function(model, keyName) {
var definition = this.getModelDefinition(model);
};`
As you can see the constraints is absent in SQL code generation. This is annoying if you use the autoupdate.
For the moment I removed the foreign keys from model definitions and added them manually manually using alter table statements.
Can you add this missing feature please!
Thanks!
Francesco