Skip to content

Commit 217ba18

Browse files
committed
bug(scopes) Mark unscoped model as .scoped to prevent injection of default scope on includes. Closes sequelize#4663
1 parent 7f5a251 commit 217ba18

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# NEXT
2+
- [FIXED] Mark unscoped model as `.scoped`, to prevent injection of default scope on includes [#4663](https://github.com/sequelize/sequelize/issues/4663)
3+
14
# 3.12.1
25
- [FIXED] Mark postgres connection as invalid if the connection is reset [#4661](https://github.com/sequelize/sequelize/pull/4661)
36
- [FIXED] Remove usage of "limit" in cases where it's unnecessary, which fixes some of the cases mentioned in [#4404] (https://github.com/sequelize/sequelize/issues/4404)

lib/model.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ Model.prototype.scope = function(option) {
11641164
, scopeName;
11651165

11661166
self.$scope = {};
1167+
self.scoped = true;
11671168

11681169
if (!option) {
11691170
return self;
@@ -1216,8 +1217,6 @@ Model.prototype.scope = function(option) {
12161217
}
12171218
});
12181219

1219-
self.scoped = true;
1220-
12211220
return self;
12221221
};
12231222

test/unit/model/scope.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
8080
it('should be able to unscope', function () {
8181
expect(Company.scope(null).$scope).to.be.empty;
8282
expect(Company.unscoped().$scope).to.be.empty;
83+
// Yes, being unscoped is also a scope - this prevents inject defaultScope, when including a scoped model, see #4663
84+
expect(Company.unscoped().scoped).to.be.ok;
8385
});
8486

8587
it('should be able to merge scopes', function() {

0 commit comments

Comments
 (0)