Skip to content

Commit

Permalink
fix(model.reload): ignore options.where and always use this.where() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantdhiman committed May 2, 2020
1 parent 6fb74c8 commit 5a4d260
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4049,8 +4049,9 @@ class Model {
* @returns {Promise<Model>}
*/
async reload(options) {
options = Utils.defaults({}, options, {
where: this.where(),
options = Utils.defaults({
where: this.where()
}, options, {
include: this._options.include || null
});

Expand Down
14 changes: 14 additions & 0 deletions test/integration/instance/reload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});

it('should use default internal where', async function() {
const user = await this.User.create({ username: 'Balak Bukhara' });
const anotherUser = await this.User.create({ username: 'John Smith' });

const primaryKey = user.get('id');

await user.reload();
expect(user.get('id')).to.equal(primaryKey);

// options.where should be ignored
await user.reload({ where: { id: anotherUser.get('id') } });
expect(user.get('id')).to.equal(primaryKey).and.not.equal(anotherUser.get('id'));
});

it('should update the values on all references to the DAO', function() {
return this.User.create({ username: 'John Doe' }).then(originalUser => {
return this.User.findByPk(originalUser.id).then(updater => {
Expand Down

0 comments on commit 5a4d260

Please sign in to comment.