From e7c6d912a46042bc995075ae637c518a820dcc93 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 1 Feb 2023 23:06:55 +0100 Subject: [PATCH] fix undeleting notes with a relation, closes #3583 --- src/becca/entities/abstract_entity.js | 4 ++-- src/becca/entities/attribute.js | 6 ++++-- src/services/notes.js | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) 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(`