diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index b92d7ec2f3..9fa006b12f 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -1790,6 +1790,19 @@ var ZoteroPane = new function() newItem.setCollections([self.collectionsView.selectedTreeRow.ref.id]); } yield newItem.save(); + for (let relItemKey of item.relatedItems) { + try { + let relItem = yield Zotero.Items.getByLibraryAndKeyAsync(item.libraryID, relItemKey); + if (relItem.addRelatedItem(newItem)) { + yield relItem.save({ + skipDateModifiedUpdate: true + }); + } + } + catch (e) { + Zotero.logError(e); + } + } }); yield self.selectItem(newItem.id); diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js index 937d3cc27b..b069c50d40 100644 --- a/test/tests/zoteroPaneTest.js +++ b/test/tests/zoteroPaneTest.js @@ -244,6 +244,22 @@ describe("ZoteroPane", function() { }) + describe("#duplicateSelectedItem()", function () { + it("should add reverse relations", async function () { + var item1 = await createDataObject('item'); + var item2 = await createDataObject('item'); + item1.addRelatedItem(item2); + await item1.saveTx(); + item2.addRelatedItem(item1); + await item2.saveTx(); + var item3 = await zp.duplicateSelectedItem(); + assert.sameMembers(item3.relatedItems, [item1.key]); + assert.sameMembers(item2.relatedItems, [item1.key]); + assert.sameMembers(item1.relatedItems, [item2.key, item3.key]); + }); + }); + + describe("#deleteSelectedItems()", function () { it("should remove an item from My Publications", function* () { var item = createUnsavedDataObject('item');