Write correct down template on one-to-many relation addition

This commit is contained in:
Aurélien Georget 2016-04-07 15:43:20 +02:00
parent c898e183c5
commit 7367e2ed61
2 changed files with 13 additions and 23 deletions

View File

@ -76,16 +76,6 @@ module.exports = function (models, modelName, details, attribute, toDrop, onlyDr
details: details,
nature: infos.nature
}));
// Template: drop the column.
// Simply make a `delete` template for this attribute wich drop the column
// with the `./builder/columns/dropColumn` template.
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn.template'), 'utf8');
models[modelName].attributes[attribute].delete.others = _.unescape(_.template(tplRelationDown)({
tableName: modelName,
attribute: attribute,
details: details
}));
} else {
// Template: create a new column thanks to the attribute's relation.
// Simply make a `create` template for this attribute wich will be added
@ -97,17 +87,17 @@ module.exports = function (models, modelName, details, attribute, toDrop, onlyDr
attribute: attribute,
details: details
}));
// Template: drop the column.
// Simply make a `delete` template for this attribute wich drop the column
// with the `./builder/columns/dropColumn` template.
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn.template'), 'utf8');
models[modelName].attributes[attribute].delete.others = _.unescape(_.template(tplRelationDown)({
tableName: modelName,
attribute: attribute,
details: details
}));
}
// Template: drop the column.
// Simply make a `delete` template for this attribute wich drop the column
// with the `./builder/columns/dropColumn` template.
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn.template'), 'utf8');
models[modelName].attributes[attribute].delete.others = _.unescape(_.template(tplRelationDown)({
tableName: modelName,
attribute: attribute,
details: details
}));
} else if (infos.verbose === 'belongsToMany') {
// Otherwise if it's a "many-to-many" relationship.

View File

@ -71,12 +71,12 @@ module.exports = function (models, modelName) {
emptyArrayForDrop = [];
emptyArrayForOthers = [];
_.forEach(models[modelName].newAttributes, function (attribute) {
if (!_.isEmpty(_.get(models[modelName].attributes, attribute + '.delete.drop'))) {
_.forEach(models[modelName].newAttributes, function (attribute, key) {
if (!_.isEmpty(_.get(models[modelName].attributes, key + '.delete.drop'))) {
emptyArrayForDrop.push(true);
}
if (!_.isEmpty(_.get(models[modelName].attributes, attribute + '.delete.others'))) {
if (!_.isEmpty(_.get(models[modelName].attributes, key + '.delete.others'))) {
emptyArrayForOthers.push(true);
}
});