不要怂,就是干,撸起袖子干!

Commit 429e8e06 by Mick Hansen

fix(instance): update should not set attributes not defined by fields, fixes #1320

1 parent 24a8ac33
Showing with 28 additions and 2 deletions
...@@ -707,7 +707,7 @@ module.exports = (function() { ...@@ -707,7 +707,7 @@ module.exports = (function() {
* @alias updateAttributes * @alias updateAttributes
*/ */
Instance.prototype.update = function(values, options) { Instance.prototype.update = function(values, options) {
return this.set(values, {attributes: options && options.attributes}).save(options); return this.set(values, {attributes: options && options.fields}).save(options);
}; };
Instance.prototype.updateAttributes = Instance.prototype.update; Instance.prototype.updateAttributes = Instance.prototype.update;
......
...@@ -82,7 +82,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -82,7 +82,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}, { }, {
fields: ['name', 'email'] fields: ['name', 'email']
}).then(function(user) { }).then(function(user) {
return user.updateAttributes({bio: 'swag'}); return user.update({bio: 'swag'});
}).then(function(user) { }).then(function(user) {
return user.reload(); return user.reload();
}).then(function(user) { }).then(function(user) {
...@@ -93,6 +93,32 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -93,6 +93,32 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
}); });
it('should not set attributes that are not specified by fields', function () {
var User = this.sequelize.define('User' + config.rand(), {
name: DataTypes.STRING,
bio: DataTypes.TEXT,
email: DataTypes.STRING
});
return User.sync({force: true}).then(function() {
return User.create({
name: 'snafu',
email: 'email'
}).then(function(user) {
return user.update({
bio: 'heyo',
email: 'heho'
}, {
fields: ['bio']
});
}).then(function(user) {
expect(user.get('name')).to.equal('snafu');
expect(user.get('email')).to.equal('email');
expect(user.get('bio')).to.equal('heyo');
});
});
});
it('updates attributes in the database', function(done) { it('updates attributes in the database', function(done) {
this.User.create({ username: 'user' }).success(function(user) { this.User.create({ username: 'user' }).success(function(user) {
expect(user.username).to.equal('user'); expect(user.username).to.equal('user');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!