From d5a9abd9114e4a2899e9541a070501966cb27400 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 11 Nov 2020 23:02:14 +0100 Subject: [PATCH] fix duplicating relations after change, closes #1405 --- src/routes/api/attributes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 8de30e9c4..345ecfae4 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -28,8 +28,10 @@ function updateNoteAttribute(req) { || body.name !== attribute.name || (body.type === 'relation' && body.value !== attribute.value)) { + let newAttribute; + if (body.type !== 'relation' || !!body.value.trim()) { - const newAttribute = attribute.createClone(body.type, body.name, body.value); + newAttribute = attribute.createClone(body.type, body.name, body.value); newAttribute.save(); } @@ -37,7 +39,7 @@ function updateNoteAttribute(req) { attribute.save(); return { - attributeId: attribute.attributeId + attributeId: newAttribute ? newAttribute.attributeId : null }; } }