diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index ce7cfdb6f..c1c894de7 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -80,14 +80,14 @@ class AbstractBeccaEntity { * * @returns {this} */ - save() { + save(opts = {}) { const entityName = this.constructor.entityName; const primaryKeyName = this.constructor.primaryKeyName; const isNewEntity = !this[primaryKeyName]; if (this.beforeSaving) { - this.beforeSaving(); + this.beforeSaving(opts); } const pojo = this.getPojoToSave(); diff --git a/src/becca/entities/battribute.js b/src/becca/entities/battribute.js index 162729c4e..ca14a90c0 100644 --- a/src/becca/entities/battribute.js +++ b/src/becca/entities/battribute.js @@ -176,8 +176,10 @@ class BAttribute extends AbstractBeccaEntity { return !(this.attributeId in this.becca.attributes); } - beforeSaving() { - this.validate(); + beforeSaving(opts = {}) { + if (!opts.skipValidation) { + this.validate(); + } this.name = sanitizeAttributeName(this.name); diff --git a/src/services/notes.js b/src/services/notes.js index 19bff76a9..50c2b0b13 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -670,7 +670,8 @@ function undeleteBranch(branchId, deleteId, taskContext) { OR (type = 'relation' AND value = ?))`, [deleteId, note.noteId, note.noteId]); for (const attribute of attributes) { - new BAttribute(attribute).save(); + // relation might point to a note which hasn't been undeleted yet and would thus throw up + new BAttribute(attribute).save({skipValidation: true}); } const noteAttachments = sql.getRows(`