Skip to content

Build your personal knowledge base with Trilium Notes

fix undeleting notes with a relation, closes #3583

zadame7c6d912a460
diff --git a/src/becca/entities/abstract_entity.js b/src/becca/entities/abstract_entity.js
index 8d28604cac..22172a1d88 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 a5c9e664bf..692b4776b3 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 1380616ae0..ce890b628f 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(`