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

Commit 24a8ac33 by Mick Hansen

fix(instance): set should use local passed options.attributes rather than global…

… options, closes #2012
1 parent d136bf6d
Showing with 28 additions and 3 deletions
...@@ -265,7 +265,7 @@ module.exports = (function() { ...@@ -265,7 +265,7 @@ module.exports = (function() {
} }
// If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object // If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
if (options.raw && !(this.options && this.options.include) && !(this.options && this.options.attributes) && !this.Model._hasBooleanAttributes && !this.Model._hasDateAttributes) { if (options.raw && !(this.options && this.options.include) && !(options && options.attributes) && !this.Model._hasBooleanAttributes && !this.Model._hasDateAttributes) {
if (Object.keys(this.dataValues).length) { if (Object.keys(this.dataValues).length) {
this.dataValues = _.extend(this.dataValues, values); this.dataValues = _.extend(this.dataValues, values);
} else { } else {
...@@ -276,8 +276,8 @@ module.exports = (function() { ...@@ -276,8 +276,8 @@ module.exports = (function() {
} else { } else {
// Loop and call set // Loop and call set
if (this.options.attributes) { if (options.attributes) {
keys = this.options.attributes; keys = options.attributes;
if (this.Model._hasVirtualAttributes) { if (this.Model._hasVirtualAttributes) {
keys = keys.concat(this.Model._virtualAttributes); keys = keys.concat(this.Model._virtualAttributes);
} }
......
...@@ -68,6 +68,31 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -68,6 +68,31 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
} }
it('should update fields that are not specified on create', 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'
}, {
fields: ['name', 'email']
}).then(function(user) {
return user.updateAttributes({bio: 'swag'});
}).then(function(user) {
return user.reload();
}).then(function(user) {
expect(user.get('name')).to.equal('snafu');
expect(user.get('email')).to.equal('email');
expect(user.get('bio')).to.equal('swag');
});
});
});
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!