From 07dd783a40f118f34a287734654fde2bff340bca Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 16 Jul 2021 14:01:47 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20error=20on=20saving=20me?= =?UTF-8?q?mber=20with=20existing=20label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Team/issues/743 Unlike tags, a label has a unique constraint on its `name`. So saving a new label on member with the same name as existing label fails with error due to unique constraint error. - adds id for new label to match existing label if they are the same name, which avoids creating a new label --- core/server/models/member.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/server/models/member.js b/core/server/models/member.js index 7fb7b84f78..79235d2010 100644 --- a/core/server/models/member.js +++ b/core/server/models/member.js @@ -155,6 +155,7 @@ const Member = ghostBookshelf.Model.extend({ return label.name.toLowerCase() === lab.get('name').toLowerCase(); }); label.name = (existingLabel && existingLabel.get('name')) || label.name; + label.id = (existingLabel && existingLabel.id) || label.id; }); model.set('labels', labelsToSave);