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 de0fbff2
authored
Sep 12, 2017
by
Aleksandr
Committed by
Sushant
Sep 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model/create): doesnot work with custom sourceKey (#8284)
1 parent
bde6d501
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletions
lib/model.js
test/integration/associations/has-many.test.js
lib/model.js
View file @
de0fbff
...
@@ -3651,7 +3651,7 @@ class Model {
...
@@ -3651,7 +3651,7 @@ class Model {
return
include
.
association
.
throughModel
.
create
(
values
,
includeOptions
);
return
include
.
association
.
throughModel
.
create
(
values
,
includeOptions
);
});
});
}
else
{
}
else
{
instance
.
set
(
include
.
association
.
foreignKey
,
this
.
get
(
this
.
constructor
.
primaryKeyAttribute
,
{
raw
:
true
}));
instance
.
set
(
include
.
association
.
foreignKey
,
this
.
get
(
include
.
association
.
sourceKey
||
this
.
constructor
.
primaryKeyAttribute
,
{
raw
:
true
}));
return
instance
.
save
(
includeOptions
);
return
instance
.
save
(
includeOptions
);
}
}
});
});
...
...
test/integration/associations/has-many.test.js
View file @
de0fbff
...
@@ -1305,6 +1305,33 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
...
@@ -1305,6 +1305,33 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
});
});
});
});
it
(
'should create with nested associated models'
,
function
()
{
const
User
=
this
.
User
,
values
=
{
username
:
'John'
,
email
:
'john@example.com'
,
tasks
:
[{
title
:
'Fix new PR'
}]
};
return
User
.
create
(
values
,
{
include
:
[
'tasks'
]
})
.
then
(
user
=>
{
// Make sure tasks are defined for created user
expect
(
user
).
to
.
have
.
property
(
'tasks'
);
expect
(
user
.
tasks
).
to
.
be
.
an
(
'array'
);
expect
(
user
.
tasks
).
to
.
lengthOf
(
1
);
expect
(
user
.
tasks
[
0
].
title
).
to
.
be
.
equal
(
values
.
tasks
[
0
].
title
,
'task title is correct'
);
return
User
.
findOne
({
where
:
{
email
:
values
.
email
}
});
})
.
then
(
user
=>
user
.
getTasks
()
.
then
(
tasks
=>
{
// Make sure tasks relationship is successful
expect
(
tasks
).
to
.
be
.
an
(
'array'
);
expect
(
tasks
).
to
.
lengthOf
(
1
);
expect
(
tasks
[
0
].
title
).
to
.
be
.
equal
(
values
.
tasks
[
0
].
title
,
'task title is correct'
);
}));
});
});
});
describe
(
'sourceKey with where clause in include'
,
()
=>
{
describe
(
'sourceKey with where clause in include'
,
()
=>
{
...
...
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