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 59b8a7bf
authored
May 26, 2020
by
Vyacheslav Aristov
Committed by
GitHub
May 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(include): check if attributes specified for included through model (#12316)
1 parent
6d87cc58
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletions
lib/model.js
test/integration/include/findAll.test.js
lib/model.js
View file @
59b8a7b
...
@@ -604,7 +604,9 @@ class Model {
...
@@ -604,7 +604,9 @@ class Model {
// pseudo include just needed the attribute logic, return
// pseudo include just needed the attribute logic, return
if
(
include
.
_pseudo
)
{
if
(
include
.
_pseudo
)
{
include
.
attributes
=
Object
.
keys
(
include
.
model
.
tableAttributes
);
if
(
!
include
.
attributes
)
{
include
.
attributes
=
Object
.
keys
(
include
.
model
.
tableAttributes
);
}
return
Utils
.
mapFinderOptions
(
include
,
include
.
model
);
return
Utils
.
mapFinderOptions
(
include
,
include
.
model
);
}
}
...
...
test/integration/include/findAll.test.js
View file @
59b8a7b
...
@@ -1835,6 +1835,50 @@ describe(Support.getTestDialectTeaser('Include'), () => {
...
@@ -1835,6 +1835,50 @@ describe(Support.getTestDialectTeaser('Include'), () => {
expect
(
parseInt
(
post
.
get
(
'commentCount'
),
10
)).
to
.
equal
(
3
);
expect
(
parseInt
(
post
.
get
(
'commentCount'
),
10
)).
to
.
equal
(
3
);
});
});
it
(
'should ignore include with attributes: [] and through: { attributes: [] } (used for aggregates)'
,
async
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
});
const
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
title
:
DataTypes
.
STRING
});
User
.
belongsToMany
(
Project
,
{
as
:
'projects'
,
through
:
'UserProject'
});
Project
.
belongsToMany
(
User
,
{
as
:
'users'
,
through
:
'UserProject'
});
await
this
.
sequelize
.
sync
({
force
:
true
});
await
User
.
create
({
name
:
Math
.
random
().
toString
(),
projects
:
[
{
title
:
Math
.
random
().
toString
()
},
{
title
:
Math
.
random
().
toString
()
},
{
title
:
Math
.
random
().
toString
()
}
]
},
{
include
:
[
User
.
associations
.
projects
]
});
const
users
=
await
User
.
findAll
({
attributes
:
[
[
this
.
sequelize
.
fn
(
'COUNT'
,
this
.
sequelize
.
col
(
'projects.id'
)),
'projectsCount'
]
],
include
:
{
association
:
User
.
associations
.
projects
,
attributes
:
[],
through
:
{
attributes
:
[]
}
},
group
:
[
'User.id'
]
});
expect
(
users
.
length
).
to
.
equal
(
1
);
const
user
=
users
[
0
];
expect
(
user
.
projects
).
not
.
to
.
be
.
ok
;
expect
(
parseInt
(
user
.
get
(
'projectsCount'
),
10
)).
to
.
equal
(
3
);
});
it
(
'should not add primary key when including and aggregating with raw: true'
,
async
function
()
{
it
(
'should not add primary key when including and aggregating with raw: true'
,
async
function
()
{
const
Post
=
this
.
sequelize
.
define
(
'Post'
,
{
const
Post
=
this
.
sequelize
.
define
(
'Post'
,
{
title
:
DataTypes
.
STRING
title
:
DataTypes
.
STRING
...
...
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