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

Commit 77ea2ee1 by Mick Hansen

fix: regression with reload() and attributes option, closes #3976

1 parent 2a18502d
# 3.3.1
- [FIXED] regression in `attributes` support for 'reload' [#3976](https://github.com/sequelize/sequelize/issues/3976)
# 3.3.0 # 3.3.0
- [FIXED] Fix `Promise#nodeify()` and `Promise#done()` not passing CLS context - [FIXED] Fix `Promise#nodeify()` and `Promise#done()` not passing CLS context
- [FIXED] Creating and dropping enums in transaction, only for PostgreSQL [#3782](https://github.com/sequelize/sequelize/issues/3782) - [FIXED] Creating and dropping enums in transaction, only for PostgreSQL [#3782](https://github.com/sequelize/sequelize/issues/3782)
......
...@@ -713,21 +713,18 @@ Instance.prototype.save = function(options) { ...@@ -713,21 +713,18 @@ Instance.prototype.save = function(options) {
* @return {Promise<this>} * @return {Promise<this>}
*/ */
Instance.prototype.reload = function(options) { Instance.prototype.reload = function(options) {
var self = this
, where = [
this.sequelize.getQueryInterface().quoteTable(this.Model.name) + '.' + this.sequelize.getQueryInterface().quoteIdentifier(this.Model.primaryKeyField) + '=?',
this.get(this.Model.primaryKeyAttribute, {raw: true})
];
options = _.defaults(options || {}, { options = _.defaults(options || {}, {
where: where, where: this.where(),
limit: 1, limit: 1,
include: this.options.include || null include: this.options.include || null
}); });
return this.Model.findOne(options).then(function(reload) { return this.Model.findOne(options).bind(this).then(function(reload) {
self.set(reload.dataValues, {raw: true, reset: true}); this.set(reload.dataValues, {
}).return(self); raw: true,
reset: true && !options.attributes
});
}).return(this);
}; };
/* /*
......
...@@ -427,6 +427,28 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -427,6 +427,28 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
}); });
it('should support updating a subset of attributes', function () {
return this.User.create({
aNumber: 1,
bNumber: 1,
}).bind(this).tap(function (user) {
return this.User.update({
bNumber: 2
}, {
where: {
id: user.get('id')
}
});
}).then(function (user) {
return user.reload({
attributes: ['bNumber']
});
}).then(function (user) {
expect(user.get('aNumber')).to.equal(1);
expect(user.get('bNumber')).to.equal(2);
});
});
it('should update read only attributes as well (updatedAt)', function() { it('should update read only attributes as well (updatedAt)', function() {
var self = this; var self = this;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!