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 84f80481
authored
Jul 22, 2018
by
u9r52sld
Committed by
Sushant
Jul 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(belongsToMany): association.add returns array of array of through records (#9700)
1 parent
f81e1385
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
lib/associations/belongs-to-many.js
test/integration/associations/belongs-to-many.test.js
lib/associations/belongs-to-many.js
View file @
84f8048
...
@@ -674,6 +674,7 @@ class BelongsToMany extends Association {
...
@@ -674,6 +674,7 @@ class BelongsToMany extends Association {
return
association
.
through
.
model
.
findAll
(
_
.
defaults
({
where
,
raw
:
true
},
options
))
return
association
.
through
.
model
.
findAll
(
_
.
defaults
({
where
,
raw
:
true
},
options
))
.
then
(
currentRows
=>
updateAssociations
(
currentRows
))
.
then
(
currentRows
=>
updateAssociations
(
currentRows
))
.
spread
(
associations
=>
associations
)
.
catch
(
error
=>
{
.
catch
(
error
=>
{
if
(
error
instanceof
EmptyResultError
)
return
updateAssociations
();
if
(
error
instanceof
EmptyResultError
)
return
updateAssociations
();
throw
error
;
throw
error
;
...
...
test/integration/associations/belongs-to-many.test.js
View file @
84f8048
...
@@ -1056,6 +1056,27 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -1056,6 +1056,27 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect
(
tasks
[
0
].
title
).
to
.
equal
(
'get started'
);
expect
(
tasks
[
0
].
title
).
to
.
equal
(
'get started'
);
});
});
});
});
it
(
'should returns array of intermediate table'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
);
const
Task
=
this
.
sequelize
.
define
(
'Task'
);
const
UserTask
=
this
.
sequelize
.
define
(
'UserTask'
);
User
.
belongsToMany
(
Task
,
{
through
:
UserTask
});
Task
.
belongsToMany
(
User
,
{
through
:
UserTask
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Promise
.
all
([
User
.
create
(),
Task
.
create
()
]).
spread
((
user
,
task
)
=>
{
return
user
.
addTask
(
task
);
}).
then
(
userTasks
=>
{
expect
(
userTasks
).
to
.
be
.
an
(
'array'
).
that
.
has
.
a
.
lengthOf
(
1
);
expect
(
userTasks
[
0
]).
to
.
be
.
an
.
instanceOf
(
UserTask
);
});
});
});
});
});
describe
(
'addMultipleAssociations'
,
()
=>
{
describe
(
'addMultipleAssociations'
,
()
=>
{
...
...
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