From f7dc6fab90a849eda71154f3c4dd10201bbf3b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 23 Mar 2015 08:34:21 +0100 Subject: [PATCH] Fix regression in prototype.save ffcaa4e7 added a "data" argument to the callback function, which shadowed the original data with the data returned by a connector. Not all connectors are returning a data object though, in which case the model instance ("this" object) is updated with wrong values. This commit fixes the problem by renaming the second callback argument to "unusedData". --- lib/dao.js | 2 +- test/manipulation.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/dao.js b/lib/dao.js index 26bec26c..ce3cad70 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -1587,7 +1587,7 @@ DataAccessObject.prototype.save = function (options, cb) { inst.trigger('save', function (saveDone) { inst.trigger('update', function (updateDone) { data = removeUndefined(data); - inst._adapter().save(modelName, inst.constructor._forDB(data), function (err, data, result) { + inst._adapter().save(modelName, inst.constructor._forDB(data), function (err, unusedData, result) { if (err) { return cb(err, inst); } diff --git a/test/manipulation.test.js b/test/manipulation.test.js index b0c9165e..f4486b61 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -340,6 +340,7 @@ describe('manipulation', function () { p.name = 'Hans'; p.save(function (err) { should.not.exist(err); + p.name.should.equal('Hans'); Person.findOne(function (err, p) { should.not.exist(err); p.name.should.equal('Hans');