Update Collection::getChildItems() when erasing item

Fixes #1188
This commit is contained in:
Dan Stillman 2017-03-07 01:54:49 -05:00
parent dd5ae0f49c
commit e9fd7f2dd1
2 changed files with 29 additions and 1 deletions

View file

@ -3944,7 +3944,7 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
Zotero.DB.requireTransaction();
// Remove item from parent collections
var parentCollectionIDs = this.collections;
var parentCollectionIDs = this._collections;
if (parentCollectionIDs) {
for (var i=0; i<parentCollectionIDs.length; i++) {
let parentCollection = yield Zotero.Collections.getAsync(parentCollectionIDs[i]);

View file

@ -227,6 +227,25 @@ describe("Zotero.Collection", function() {
assert.lengthOf(collection.getChildItems(false, true), 1);
})
it("should not include removed items", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [ col.id ] });
assert.lengthOf(col.getChildItems(), 1);
item.setCollections([]);
yield item.saveTx();
Zotero.debug(col.getChildItems());
assert.lengthOf(col.getChildItems(), 0);
});
it("should not include deleted items", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [ col.id ] });
assert.lengthOf(col.getChildItems(), 1);
yield item.erase();
Zotero.debug(col.getChildItems());
assert.lengthOf(col.getChildItems(), 0);
});
})
describe("#toJSON()", function () {
@ -293,5 +312,14 @@ describe("Zotero.Collection", function() {
]
);
});
it("should not include deleted items", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [col.id] });
assert.lengthOf(col.getDescendents(), 1);
yield item.eraseTx();
assert.lengthOf(col.getDescendents(), 0);
});
});
})