www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 531170353b395d2f63cc4b5f5aac5f1eca1953eb
parent c0143300c426a586b40acd448fa9c4da39d48b58
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun,  1 Oct 2017 22:04:11 -0400

Fix bidirectional relations on Duplicate Item

Diffstat:
Mchrome/content/zotero/zoteroPane.js | 13+++++++++++++
Mtest/tests/zoteroPaneTest.js | 16++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git 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 @@ -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');