Allows unknown properties to be saved for non-strict models
See https://github.com/strongloop/loopback/issues/199
This commit is contained in:
parent
4765fbed62
commit
44a62d01af
|
@ -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 () {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue