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

This commit is contained in:
Abdullah Atta
2024-04-26 13:56:28 +05:00
parent 9a58430b5d
commit f047552f18

View File

@@ -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")