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

Commit 4c674e29 by Sushant Committed by GitHub

fix(scope): don't modify original scope definition (#12207)

1 parent e78da7f9
Showing with 24 additions and 3 deletions
......@@ -1562,7 +1562,8 @@ class Model {
if (scope) {
this._conformIncludes(scope, this);
this._assignOptions(self._scope, scope);
// clone scope so it doesn't get modified
this._assignOptions(self._scope, Utils.cloneDeep(scope));
self._scopeNames.push(scopeName ? scopeName : 'defaultScope');
} else {
throw new sequelizeErrors.SequelizeScopeError(`Invalid scope ${scopeName} called.`);
......
......@@ -207,6 +207,27 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('should be keep original scope definition clean', () => {
expect(Company.scope('projects', 'users', 'alsoUsers')._scope).to.deep.equal({
include: [
{ model: Project },
{ model: User, where: { something: 42 } }
]
});
expect(Company.options.scopes.alsoUsers).to.deep.equal({
include: [
{ model: User, where: { something: 42 } }
]
});
expect(Company.options.scopes.users).to.deep.equal({
include: [
{ model: User }
]
});
});
it('should be able to override the default scope', () => {
expect(Company.scope('somethingTrue')._scope).to.deep.equal(scopes.somethingTrue);
});
......@@ -516,4 +537,4 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
\ No newline at end of file
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!