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 e07a7bea
authored
Mar 22, 2019
by
Simon Schick
Committed by
Erik Seliger
Mar 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query-generator): correctly treat projection inversion in include default scope (#10597)
Fixes #10399
1 parent
db16cd56
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
10 deletions
lib/dialects/abstract/query-generator.js
lib/model.js
test/integration/model/scope/find.test.js
lib/dialects/abstract/query-generator.js
View file @
e07a7be
...
...
@@ -1425,6 +1425,7 @@ class QueryGenerator {
// includeIgnoreAttributes is used by aggregate functions
if (topLevelInfo.options.includeIgnoreAttributes !== false) {
include.model._expandAttributes(include);
const includeAttributes = include.attributes.map(attr => {
let attrAs = attr;
let verbatim = false;
...
...
lib/model.js
View file @
e07a7be
...
...
@@ -3082,19 +3082,20 @@ class Model {
}
static
_expandAttributes
(
options
)
{
if
(
_
.
isPlainObject
(
options
.
attributes
))
{
let
attributes
=
Object
.
keys
(
this
.
rawAttributes
);
if
(
options
.
attributes
.
exclude
)
{
attributes
=
attributes
.
filter
(
elem
=>
!
options
.
attributes
.
exclude
.
includes
(
elem
));
}
if
(
!
_
.
isPlainObject
(
options
.
attributes
))
{
return
;
}
let
attributes
=
Object
.
keys
(
this
.
rawAttributes
);
if
(
options
.
attributes
.
in
clude
)
{
attributes
=
attributes
.
concat
(
options
.
attributes
.
include
);
}
if
(
options
.
attributes
.
ex
clude
)
{
attributes
=
attributes
.
filter
(
elem
=>
!
options
.
attributes
.
exclude
.
includes
(
elem
)
);
}
options
.
attributes
=
attributes
;
if
(
options
.
attributes
.
include
)
{
attributes
=
attributes
.
concat
(
options
.
attributes
.
include
);
}
options
.
attributes
=
attributes
;
}
// Inject _scope into options.
...
...
test/integration/model/scope/find.test.js
View file @
e07a7be
...
...
@@ -46,6 +46,18 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
});
this
.
DefaultScopeExclude
=
this
.
sequelize
.
define
(
'DefaultScopeExclude'
,
{
name
:
Sequelize
.
STRING
},
{
defaultScope
:
{
attributes
:
{
exclude
:
[
'name'
]
}
}
});
this
.
ScopeMe
.
hasMany
(
this
.
DefaultScopeExclude
);
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
const
records
=
[
{
username
:
'tony'
,
email
:
'tony@sequelizejs.com'
,
access_level
:
3
,
other_value
:
7
,
parent_id
:
1
},
...
...
@@ -119,5 +131,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
user
.
username
).
to
.
equal
(
'fake'
);
});
});
it
(
'should work when included with default scope'
,
function
()
{
return
this
.
ScopeMe
.
findOne
({
include
:
[
this
.
DefaultScopeExclude
]
});
});
});
});
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