mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
Write correct down template on one-to-many relation addition
This commit is contained in:
parent
c898e183c5
commit
7367e2ed61
@ -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.
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user