diff --git a/src/becca/entities/abstract_entity.js b/src/becca/entities/abstract_entity.js index 8d28604ca..22172a1d8 100644 --- a/src/becca/entities/abstract_entity.js +++ b/src/becca/entities/abstract_entity.js @@ -80,14 +80,14 @@ class AbstractEntity { * * @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/attribute.js b/src/becca/entities/attribute.js index a5c9e664b..692b4776b 100644 --- a/src/becca/entities/attribute.js +++ b/src/becca/entities/attribute.js @@ -176,8 +176,10 @@ class Attribute extends AbstractEntity { 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 1380616ae..ce890b628 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -661,7 +661,8 @@ function undeleteBranch(branchId, deleteId, taskContext) { OR (type = 'relation' AND value = ?))`, [deleteId, note.noteId, note.noteId]); for (const attribute of attributes) { - new Attribute(attribute).save(); + // relation might point to a note which hasn't been undeleted yet and would thus throw up + new Attribute(attribute).save({skipValidation: true}); } const childBranchIds = sql.getColumn(`