Skip to content

Commit

Permalink
fix(addScope): only throw when defaultScope is defined (#9703)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawton Spelliscy authored and sushantdhiman committed Jul 22, 2018
1 parent 532286f commit be8760d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ class Model {
override: false
}, options);

if ((name === 'defaultScope' || name in this.options.scopes) && options.override === false) {
if ((name === 'defaultScope' && Object.keys(this.options.defaultScope).length > 0 || name in this.options.scopes) && options.override === false) {
throw new Error('The scope ' + name + ' already exists. Pass { override: true } as options to silence this error');
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/model/scope.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).to.throw('The scope defaultScope already exists. Pass { override: true } as options to silence this error');
});

it('should not warn if default scope is not defined', () => {
const Model = current.define('model');

expect(() => {
Model.addScope('defaultScope', {});
}).not.to.throw();
});

it('allows me to override a default scope', () => {
Company.addScope('defaultScope', {
include: [Project]
Expand Down

0 comments on commit be8760d

Please sign in to comment.