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

Commit 0da021cd by Brett Vitaz Committed by Sushant

feat(scopes): allow scope `group`s to be concatenated (#7957)

1 parent c528f6d6
Showing with 15 additions and 1 deletions
...@@ -1351,7 +1351,7 @@ class Model { ...@@ -1351,7 +1351,7 @@ class Model {
_.assignWith(self._scope, scope, (objectValue, sourceValue, key) => { _.assignWith(self._scope, scope, (objectValue, sourceValue, key) => {
if (key === 'where') { if (key === 'where') {
return Array.isArray(sourceValue) ? sourceValue : _.assign(objectValue || {}, sourceValue); return Array.isArray(sourceValue) ? sourceValue : _.assign(objectValue || {}, sourceValue);
} else if (['attributes', 'include'].indexOf(key) >= 0 && Array.isArray(objectValue) && Array.isArray(sourceValue)) { } else if (['attributes', 'include', 'group'].indexOf(key) >= 0 && Array.isArray(objectValue) && Array.isArray(sourceValue)) {
return objectValue.concat(sourceValue); return objectValue.concat(sourceValue);
} }
......
...@@ -41,6 +41,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -41,6 +41,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
projects: { projects: {
include: [Project] include: [Project]
}, },
groupByCompanyId: {
group: ['company.id']
},
groupByProjectId: {
group: ['project.id'],
include: [Project]
},
noArgs() { noArgs() {
// This does not make much sense, since it does not actually need to be in a function, // This does not make much sense, since it does not actually need to be in a function,
// In reality it could be used to do for example new Date or random in the scope - but we want it deterministic // In reality it could be used to do for example new Date or random in the scope - but we want it deterministic
...@@ -215,6 +222,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -215,6 +222,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
Company.scope('doesntexist'); Company.scope('doesntexist');
}).to.throw('Invalid scope doesntexist called.'); }).to.throw('Invalid scope doesntexist called.');
}); });
it('should concatenate scope groups', () => {
expect(Company.scope('groupByCompanyId', 'groupByProjectId')._scope).to.deep.equal({
group: ['company.id', 'project.id'],
include: [{ model: Project }]
});
});
}); });
describe('addScope', () => { describe('addScope', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!