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 f2b0aec1
authored
Jul 06, 2019
by
Jorge López Fernández
Committed by
Sushant
Jul 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): don't alter original scopes when combining them (#10722)
1 parent
75b95dc5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
3 deletions
lib/model.js
lib/utils.js
test/unit/model/scope.test.js
lib/model.js
View file @
f2b0aec
...
@@ -811,6 +811,12 @@ class Model {
...
@@ -811,6 +811,12 @@ class Model {
}
}
});
});
}
}
// If we have a possible object/array to clone, we try it.
// Otherwise, we return the original value when it's not undefined,
// or the resulting object in that case.
if
(
srcValue
)
{
return
Utils
.
cloneDeep
(
srcValue
,
true
);
}
return
srcValue
===
undefined
?
objValue
:
srcValue
;
return
srcValue
===
undefined
?
objValue
:
srcValue
;
}
}
...
...
lib/utils.js
View file @
f2b0aec
...
@@ -123,7 +123,7 @@ function formatNamedParameters(sql, parameters, dialect) {
...
@@ -123,7 +123,7 @@ function formatNamedParameters(sql, parameters, dialect) {
}
}
exports
.
formatNamedParameters
=
formatNamedParameters
;
exports
.
formatNamedParameters
=
formatNamedParameters
;
function
cloneDeep
(
obj
)
{
function
cloneDeep
(
obj
,
onlyPlain
)
{
obj
=
obj
||
{};
obj
=
obj
||
{};
return
_
.
cloneDeepWith
(
obj
,
elem
=>
{
return
_
.
cloneDeepWith
(
obj
,
elem
=>
{
// Do not try to customize cloning of arrays or POJOs
// Do not try to customize cloning of arrays or POJOs
...
@@ -131,8 +131,9 @@ function cloneDeep(obj) {
...
@@ -131,8 +131,9 @@ function cloneDeep(obj) {
return
undefined
;
return
undefined
;
}
}
// Don't clone stuff that's an object, but not a plain one - fx example sequelize models and instances
// If we specified to clone only plain objects & arrays, we ignore everyhing else
if
(
typeof
elem
===
'object'
)
{
// In any case, don't clone stuff that's an object, but not a plain one - fx example sequelize models and instances
if
(
onlyPlain
||
typeof
elem
===
'object'
)
{
return
elem
;
return
elem
;
}
}
...
...
test/unit/model/scope.test.js
View file @
f2b0aec
...
@@ -112,6 +112,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -112,6 +112,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it
(
'should unite attributes with array'
,
()
=>
{
it
(
'should unite attributes with array'
,
()
=>
{
expect
(
User
.
scope
(
'aScope'
,
'defaultScope'
).
_scope
.
attributes
).
to
.
deep
.
equal
({
exclude
:
[
'value'
,
'password'
]
});
expect
(
User
.
scope
(
'aScope'
,
'defaultScope'
).
_scope
.
attributes
).
to
.
deep
.
equal
({
exclude
:
[
'value'
,
'password'
]
});
});
});
it
(
'should not modify the original scopes when merging them'
,
()
=>
{
expect
(
User
.
scope
(
'defaultScope'
,
'aScope'
).
options
.
defaultScope
.
attributes
).
to
.
deep
.
equal
({
exclude
:
[
'password'
]
});
});
});
});
it
(
'defaultScope should be an empty object if not overridden'
,
()
=>
{
it
(
'defaultScope should be an empty object if not overridden'
,
()
=>
{
...
...
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