From b1e324ddfbcc7d44fb17a4f85f4654f5c0f0260e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 27 Dec 2020 19:49:50 -0500 Subject: [PATCH] Fix marking of childItems as loaded for non-top-level items Now that attachments and notes can have child items too --- chrome/content/zotero/xpcom/data/items.js | 11 ++++++++--- test/tests/itemsTest.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 99aabbc023..9a08cbb6ff 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -594,6 +594,9 @@ Zotero.Items = function() { }); }; + // + // Attachments + // var sql = "SELECT parentItemID, A.itemID, value AS title, " + "CASE WHEN DI.itemID IS NULL THEN 0 ELSE 1 END AS trashed " + "FROM itemAttachments A " @@ -742,9 +745,11 @@ Zotero.Items = function() { ids.forEach(id => setAnnotationItem(id, [])); } - // Mark all top-level items as having child items loaded - sql = "SELECT itemID FROM items I WHERE libraryID=?" + idSQL + " AND itemID NOT IN " - + "(SELECT itemID FROM itemAttachments UNION SELECT itemID FROM itemNotes)"; + // Mark either all passed items or all items as having child items loaded + sql = "SELECT itemID FROM items I WHERE libraryID=?"; + if (idSQL) { + sql += idSQL; + } yield Zotero.DB.queryAsync( sql, params, diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js index aa4798acb4..562b0d4f1c 100644 --- a/test/tests/itemsTest.js +++ b/test/tests/itemsTest.js @@ -624,4 +624,16 @@ describe("Zotero.Items", function () { ); }); }); + + describe("#_loadChildItems()", function () { + it("should mark child items as loaded for an attachment", async function () { + var attachment = await importPDFAttachment(); + var itemID = attachment.id; + Zotero.Items.unload([itemID]); + attachment = await Zotero.Items.getAsync(itemID); + await attachment.loadDataType('childItems'); + assert.isTrue(attachment._loaded.childItems); + attachment.getAnnotations(); + }); + }); });