Merge pull request #1506 from strapi/fix-one-way

Fix loose oneWay relation on update content type
This commit is contained in:
Jim LAURIE 2018-07-03 17:34:28 +02:00 committed by GitHub
commit e08afef426
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -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 }]);

View File

@ -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)) {