Skip to content

Build your personal knowledge base with Trilium Notes

fix undeleting note when its relation points to yet-undeleted note

zadam64e7150765c5
diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js
index ce7cfdb6fc..c1c894de74 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 162729c4e3..ca14a90c0f 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 19bff76a9d..50c2b0b130 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(`