Fix error when updating objects on some platforms

On some platforms. Sequelize.update() returns 0 even if the rows were
found, if no fields have been changed.
pull/54/merge
Candid Dauth 2016-12-27 15:25:02 +01:00
rodzic 73d97e7194
commit 670a8dd56b
1 zmienionych plików z 5 dodań i 6 usunięć

Wyświetl plik

@ -201,15 +201,14 @@ module.exports = function(Database) {
return utils.promiseAuto({
oldData: () => {
if(makeHistory)
return this._getPadObject(type, padId, objId);
// Fetch the old object for the history, but also to make sure that the object exists. Unfortunately,
// we cannot rely on the return value of the update() method, as on some platforms it returns 0 even
// if the object was found (but no fields were changed)
return this._getPadObject(type, padId, objId);
},
update: (oldData) => {
return this._conn.model(type).update(data, { where: { id: objId, padId: padId } }).then((res) => {
if(res[0] == 0)
throw new Error(type + " " + objId + " of pad " + padId + "could not be found.");
});
return this._conn.model(type).update(data, { where: { id: objId, padId: padId } });
},
newData: (update) => {