From eff46b5cb1e46e4896a8e81f5be28ec7dd61875f Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Mon, 2 Jul 2018 15:41:53 +0200 Subject: [PATCH] Not clear oneWay relation on model update fix #1477 --- .../controllers/ContentTypeBuilder.js | 2 +- .../services/ContentTypeBuilder.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/controllers/ContentTypeBuilder.js b/packages/strapi-plugin-content-type-builder/controllers/ContentTypeBuilder.js index 8849d3f31a..ba08e31551 100755 --- a/packages/strapi-plugin-content-type-builder/controllers/ContentTypeBuilder.js +++ b/packages/strapi-plugin-content-type-builder/controllers/ContentTypeBuilder.js @@ -169,7 +169,7 @@ module.exports = { strapi.reload.isWatching = false; - const clearRelationsErrors = Service.clearRelations(model); + const clearRelationsErrors = Service.clearRelations(model, undefined, true); if (!_.isEmpty(clearRelationsErrors)) { return ctx.badRequest(null, [{ messages: clearRelationsErrors }]); diff --git a/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js b/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js index 1be73429fc..eebcc5d686 100755 --- a/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js +++ b/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js @@ -241,7 +241,7 @@ module.exports = { return [attributesNotConfigurable, errors]; }, - clearRelations: (model, source) => { + clearRelations: (model, source, force) => { const errors = []; const structure = { models: strapi.models, @@ -259,10 +259,10 @@ module.exports = { Object.keys(models).forEach(name => { const relationsToDelete = _.get(plugin ? strapi.plugins[plugin].models[name] : strapi.models[name], 'associations', []).filter(association => { if (source) { - return association[association.type] === model && association.plugin === source; + return association[association.type] === model && association.plugin === source && (association.nature !== 'oneWay' || force); } - return association[association.type] === model; + return association[association.type] === model && (association.nature !== 'oneWay' || force); }); if (!_.isEmpty(relationsToDelete)) {