Skip to content

Commit 77ea2ee

Browse files
committed
fix: regression with reload() and attributes option, closes sequelize#3976
1 parent 2a18502 commit 77ea2ee

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 3.3.1
2+
- [FIXED] regression in `attributes` support for 'reload' [#3976](https://github.com/sequelize/sequelize/issues/3976)
3+
14
# 3.3.0
25
- [FIXED] Fix `Promise#nodeify()` and `Promise#done()` not passing CLS context
36
- [FIXED] Creating and dropping enums in transaction, only for PostgreSQL [#3782](https://github.com/sequelize/sequelize/issues/3782)

lib/instance.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -713,21 +713,18 @@ Instance.prototype.save = function(options) {
713713
* @return {Promise<this>}
714714
*/
715715
Instance.prototype.reload = function(options) {
716-
var self = this
717-
, where = [
718-
this.sequelize.getQueryInterface().quoteTable(this.Model.name) + '.' + this.sequelize.getQueryInterface().quoteIdentifier(this.Model.primaryKeyField) + '=?',
719-
this.get(this.Model.primaryKeyAttribute, {raw: true})
720-
];
721-
722716
options = _.defaults(options || {}, {
723-
where: where,
717+
where: this.where(),
724718
limit: 1,
725719
include: this.options.include || null
726720
});
727721

728-
return this.Model.findOne(options).then(function(reload) {
729-
self.set(reload.dataValues, {raw: true, reset: true});
730-
}).return(self);
722+
return this.Model.findOne(options).bind(this).then(function(reload) {
723+
this.set(reload.dataValues, {
724+
raw: true,
725+
reset: true && !options.attributes
726+
});
727+
}).return(this);
731728
};
732729

733730
/*

test/integration/instance.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,28 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
427427
});
428428
});
429429

430+
it('should support updating a subset of attributes', function () {
431+
return this.User.create({
432+
aNumber: 1,
433+
bNumber: 1,
434+
}).bind(this).tap(function (user) {
435+
return this.User.update({
436+
bNumber: 2
437+
}, {
438+
where: {
439+
id: user.get('id')
440+
}
441+
});
442+
}).then(function (user) {
443+
return user.reload({
444+
attributes: ['bNumber']
445+
});
446+
}).then(function (user) {
447+
expect(user.get('aNumber')).to.equal(1);
448+
expect(user.get('bNumber')).to.equal(2);
449+
});
450+
});
451+
430452
it('should update read only attributes as well (updatedAt)', function() {
431453
var self = this;
432454

0 commit comments

Comments
 (0)