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

Commit 6f9a53bf by Brian Woodward Committed by Jan Aagaard Meier

Consecutive function scopes (#7066)

* add failing unit test

* use .slice instead of .splice to get arguments for scope functions

* add message to changelog.md
1 parent de60eb50
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
- [FIXED] Custom error messages used for incorrect eager loading [#7005](https://github.com/sequelize/sequelize/pull/7005) - [FIXED] Custom error messages used for incorrect eager loading [#7005](https://github.com/sequelize/sequelize/pull/7005)
- [FIXED] Enforce unique association aliases [#7025](https://github.com/sequelize/sequelize/pull/7025) - [FIXED] Enforce unique association aliases [#7025](https://github.com/sequelize/sequelize/pull/7025)
- [FIXED] Information warnings when findAll is given incorrect inputs [#7047](https://github.com/sequelize/sequelize/pull/7047) - [FIXED] Information warnings when findAll is given incorrect inputs [#7047](https://github.com/sequelize/sequelize/pull/7047)
- [FIXED] scope method syntax loses parameters when used multiple times [#7058](https://github.com/sequelize/sequelize/issues/7058)
## BC breaks: ## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type - `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
......
...@@ -1303,7 +1303,7 @@ class Model { ...@@ -1303,7 +1303,7 @@ class Model {
if (!!option.method) { if (!!option.method) {
if (Array.isArray(option.method) && !!self.options.scopes[option.method[0]]) { if (Array.isArray(option.method) && !!self.options.scopes[option.method[0]]) {
scopeName = option.method[0]; scopeName = option.method[0];
scope = self.options.scopes[scopeName].apply(self, option.method.splice(1)); scope = self.options.scopes[scopeName].apply(self, option.method.slice(1));
} }
else if (!!self.options.scopes[option.method]) { else if (!!self.options.scopes[option.method]) {
scopeName = option.method; scopeName = option.method;
......
...@@ -161,6 +161,21 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -161,6 +161,21 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('should work with consecutive function scopes', function () {
var scope = {method: ['actualValue', 11]};
expect(Company.scope(scope)._scope).to.deep.equal({
where: {
other_value: 11
}
});
expect(Company.scope(scope)._scope).to.deep.equal({
where: {
other_value: 11
}
});
});
it('should be able to merge two scoped includes', function () { it('should be able to merge two scoped includes', function () {
expect(Company.scope('users', 'projects')._scope).to.deep.equal({ expect(Company.scope('users', 'projects')._scope).to.deep.equal({
include: [ include: [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!