diff --git a/lib/dao.js b/lib/dao.js index f5edfe13..9025cbf7 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -876,8 +876,9 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb var typedData = {}; for (var key in data) { + // Convert the properties by type inst[key] = data[key]; - typedData[key] = inst.__data[key]; + typedData[key] = inst[key]; } inst._adapter().updateAttributes(model, getIdValue(inst.constructor, inst), inst.constructor._forDB(typedData), function (err) { @@ -886,7 +887,6 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb for (var key in data) { inst.__dataWas[key] = inst.__data[key]; } - ; } done.call(inst, function () { saveDone.call(inst, function () { diff --git a/package.json b/package.json index 495f0414..4d725ab8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-datasource-juggler", - "version": "1.3.3", + "version": "1.3.4", "description": "LoopBack DataSoure Juggler", "keywords": [ "StrongLoop", diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 8be22fac..e826e188 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -486,6 +486,32 @@ describe('DataSource define model', function () { }); + it('should update the instance with unknown properties', function (done) { + var ds = new DataSource('memory');// define models + Post = ds.define('Post', { + title: { type: String, length: 255, index: true }, + content: { type: String } + }); + + Post.create({title: 'a', content: 'AAA'}, function (err, post) { + post.updateAttributes({title: 'b', xyz: 'xyz'}, function (err, p) { + should.not.exist(err); + p.id.should.be.equal(post.id); + p.content.should.be.equal(post.content); + p.xyz.should.be.equal('xyz'); + + Post.findById(post.id, function (err, p) { + p.id.should.be.equal(post.id); + p.content.should.be.equal(post.content); + p.xyz.should.be.equal('xyz'); + p.title.should.be.equal('b'); + done(); + }); + }); + + }); + }); + it('injects id by default', function (done) { var ds = new ModelBuilder();