Fix foreign key constraint error for collections with all-numeric keys
This was like a lottery where instead of winning something your library stopped syncing.
This commit is contained in:
parent
8bd35ee0d4
commit
c2a637472e
2 changed files with 20 additions and 2 deletions
|
@ -3545,8 +3545,8 @@ Zotero.Item.prototype.setCollections = function (collectionIDsOrKeys) {
|
|||
|
||||
// Convert any keys to ids
|
||||
var collectionIDs = collectionIDsOrKeys.map(function (val) {
|
||||
if (parseInt(val) == val) {
|
||||
return parseInt(val);
|
||||
if (typeof val == 'number') {
|
||||
return val;
|
||||
}
|
||||
var id = this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, val);
|
||||
if (!id) {
|
||||
|
|
|
@ -568,6 +568,24 @@ describe("Zotero.Item", function () {
|
|||
})
|
||||
|
||||
|
||||
describe("#setCollections()", function () {
|
||||
it("should add a collection with an all-numeric key", async function () {
|
||||
var col = new Zotero.Collection();
|
||||
col.libraryID = Zotero.Libraries.userLibraryID;
|
||||
col.key = '23456789';
|
||||
await col.loadPrimaryData();
|
||||
col.name = 'Test';
|
||||
var id = await col.saveTx();
|
||||
|
||||
var item = createUnsavedDataObject('item');
|
||||
item.setCollections([col.key]);
|
||||
await item.saveTx();
|
||||
|
||||
assert.isTrue(col.hasItem(item));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("#numAttachments()", function () {
|
||||
it("should include child attachments", function* () {
|
||||
var item = yield createDataObject('item');
|
||||
|
|
Loading…
Reference in a new issue