Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix attachment not getting detached from note's content

Abdullah Attaf047552f1819
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")