From 64e7150765c5f28151fb7dbe9e14ba14f5682501 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 24 Jan 2023 09:43:10 +0100 Subject: [PATCH] fix undeleting note when its relation points to yet-undeleted note --- src/becca/entities/abstract_becca_entity.js | 4 ++-- src/becca/entities/battribute.js | 6 ++++-- src/services/notes.js | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) 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(`