🐛 Fixed error on saving member with existing label

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
This commit is contained in:
Rishabh 2021-07-16 14:01:47 +05:30
parent 768709ce88
commit 07dd783a40

View File

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