Fix bidirectional relations on Duplicate Item
This commit is contained in:
parent
c0143300c4
commit
531170353b
2 changed files with 29 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue