From f047552f18191c97c294eae937be0367442cec5d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 26 Apr 2024 13:56:28 +0500 Subject: [PATCH] core: fix attachment not getting detached from note's content --- packages/core/src/collections/attachments.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/collections/attachments.ts b/packages/core/src/collections/attachments.ts index 2786c7a91..762fd4c8e 100644 --- a/packages/core/src/collections/attachments.ts +++ b/packages/core/src/collections/attachments.ts @@ -213,8 +213,8 @@ export class Attachments implements ICollection { if (!localOnly) { await this.detach(attachment); } + await this.db.relations.unlinkOfType("attachment", [attachment.id]); await this.collection.softDelete([attachment.id]); - await this.db.relations.from(attachment, "note").unlink(); return true; } return false; @@ -222,7 +222,7 @@ export class Attachments implements ICollection { async detach(attachment: Attachment) { for (const note of await this.db.relations - .from(attachment, "note") + .to(attachment, "note") .selector.fields(["notes.contentId"]) .items()) { if (!note.contentId) continue; @@ -233,7 +233,7 @@ export class Attachments implements ICollection { } private async canDetach(attachment: Attachment) { - const linkedNotes = await this.db.relations.from(attachment, "note").get(); + const linkedNotes = await this.db.relations.to(attachment, "note").get(); return ( (await this.db.relations .to({ ids: linkedNotes.map((n) => n.toId), type: "note" }, "vault")