Remove related-item relations when deleting item

This commit is contained in:
Dan Stillman 2017-05-19 08:30:00 -04:00
parent 8edd8830da
commit fc4eb5308f
2 changed files with 30 additions and 2 deletions

View file

@ -1167,6 +1167,8 @@ for (let name of ['deleted', 'inPublications']) {
/**
* Relate this item to another. A separate save is required.
*
* @param {Zotero.Item}
* @return {Boolean}
*/
@ -4038,8 +4040,14 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
}
}
// Flag related items for notification
// TEMP: Do something with relations
// Remove related-item relations pointing to this item
var relatedItems = Zotero.Relations.getByPredicateAndObject(
'item', Zotero.Relations.relatedItemPredicate, Zotero.URI.getItemURI(this)
);
for (let relatedItem of relatedItems) {
relatedItem.removeRelatedItem(this);
relatedItem.save();
}
// Clear fulltext cache
if (this.isAttachment()) {

View file

@ -1069,6 +1069,26 @@ describe("Zotero.Item", function () {
})
describe("#_eraseData()", function () {
it("should remove relations pointing to this item", function* () {
var item1 = yield createDataObject('item');
var item2 = yield createDataObject('item');
item1.addRelatedItem(item2);
yield item1.saveTx();
item2.addRelatedItem(item1);
yield item2.saveTx();
yield item1.eraseTx();
assert.lengthOf(item2.relatedItems, 0);
yield assert.eventually.equal(
Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM itemRelations WHERE itemID=?", item2.id),
0
);
});
});
describe("#multiDiff", function () {
it("should return set of alternatives for differing fields in other items", function* () {
var type = 'item';