Include only related-item relations when duplicating items
Don't include linked-object or replaced-item relations. Previously, if you duplicated an item, modified it to represent a different source, and dragged it to another library where you had already copied the original item, the new item wouldn't be transferred. https://forums.zotero.org/discussion/comment/353246/#Comment_353246
This commit is contained in:
parent
c5a4871a6a
commit
617564982c
2 changed files with 27 additions and 1 deletions
|
@ -4006,7 +4006,23 @@ Zotero.Item.prototype.clone = function (libraryID, options = {}) {
|
||||||
|
|
||||||
if (sameLibrary) {
|
if (sameLibrary) {
|
||||||
// DEBUG: this will add reverse-only relateds too
|
// DEBUG: this will add reverse-only relateds too
|
||||||
newItem.setRelations(this.getRelations());
|
let relations = this.getRelations();
|
||||||
|
|
||||||
|
// Only include certain relations
|
||||||
|
let predicates = [
|
||||||
|
Zotero.Relations.relatedItemPredicate,
|
||||||
|
];
|
||||||
|
let any = false;
|
||||||
|
let newRelations = {};
|
||||||
|
for (let predicate of predicates) {
|
||||||
|
if (relations[predicate]) {
|
||||||
|
newRelations[predicate] = relations[predicate];
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (any) {
|
||||||
|
newItem.setRelations(newRelations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
|
|
|
@ -1336,6 +1336,16 @@ describe("Zotero.Item", function () {
|
||||||
var newItem = item.clone();
|
var newItem = item.clone();
|
||||||
assert.sameDeepMembers(item.getCreators(), newItem.getCreators());
|
assert.sameDeepMembers(item.getCreators(), newItem.getCreators());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("shouldn't copy linked-item relation", async function () {
|
||||||
|
var group = await getGroup();
|
||||||
|
var groupItem = await createDataObject('item', { libraryID: group.libraryID });
|
||||||
|
var item = await createDataObject('item');
|
||||||
|
await item.addLinkedItem(groupItem);
|
||||||
|
assert.equal(await item.getLinkedItem(group.libraryID), groupItem);
|
||||||
|
var newItem = item.clone();
|
||||||
|
assert.isEmpty(Object.keys(newItem.toJSON().relations));
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#moveToLibrary()", function () {
|
describe("#moveToLibrary()", function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue