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 4cc7dc8a
authored
Apr 17, 2019
by
DC
Committed by
Sushant
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): handle virtual attributes in includes (#10785)
1 parent
93e64a9a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
lib/model.js
test/integration/model/attributes/types.test.js
lib/model.js
View file @
4cc7dc8
...
...
@@ -584,10 +584,9 @@ class Model {
if
(
include
.
attributes
&&
!
options
.
raw
)
{
include
.
model
.
_expandAttributes
(
include
);
// Need to make sure virtuals are mapped before setting originalAttributes
include
=
Utils
.
mapFinderOptions
(
include
,
include
.
model
);
include
.
originalAttributes
=
this
.
_injectDependentVirtualAttributes
(
include
.
attributes
);
include
.
originalAttributes
=
include
.
attributes
.
slice
(
0
);
include
=
Utils
.
mapFinderOptions
(
include
,
include
.
model
);
if
(
include
.
attributes
.
length
)
{
_
.
each
(
include
.
model
.
primaryKeys
,
(
attr
,
key
)
=>
{
...
...
@@ -699,7 +698,7 @@ class Model {
// Validate child includes
if
(
include
.
hasOwnProperty
(
'include'
))
{
this
.
_validateIncludedElements
.
call
(
include
.
model
,
include
,
tableNames
,
options
);
this
.
_validateIncludedElements
.
call
(
include
.
model
,
include
,
tableNames
);
}
return
include
;
...
...
test/integration/model/attributes/types.test.js
View file @
4cc7dc8
...
...
@@ -40,6 +40,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this
.
Project
=
this
.
sequelize
.
define
(
'project'
,
{});
this
.
Task
.
belongsTo
(
this
.
User
);
this
.
User
.
hasMany
(
this
.
Task
);
this
.
Project
.
belongsToMany
(
this
.
User
,
{
through
:
'project_user'
});
this
.
User
.
belongsToMany
(
this
.
Project
,
{
through
:
'project_user'
});
...
...
@@ -173,6 +174,23 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
user
).
to
.
include
.
all
.
keys
([
'field2'
]);
});
});
it
(
'should be able to include model with virtual attributes'
,
function
()
{
return
this
.
User
.
create
({}).
then
(
user
=>
{
return
user
.
createTask
();
}).
then
(()
=>
{
return
this
.
Task
.
findAll
({
include
:
[{
attributes
:
[
'field2'
,
'id'
],
model
:
this
.
User
}]
});
}).
then
(
tasks
=>
{
const
user
=
tasks
[
0
].
user
.
get
();
expect
(
user
.
field2
).
to
.
equal
(
42
);
});
});
});
});
});
...
...
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