Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 0da021cd
authored
Aug 30, 2017
by
Brett Vitaz
Committed by
Sushant
Aug 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(scopes): allow scope `group`s to be concatenated (#7957)
1 parent
c528f6d6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletions
lib/model.js
test/unit/model/scope.test.js
lib/model.js
View file @
0da021c
...
@@ -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
);
}
}
...
...
test/unit/model/scope.test.js
View file @
0da021c
...
@@ -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'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment