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 7d5dce9d
authored
Feb 24, 2016
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5479 from luin/feature/through-query
Support querying the through model
2 parents
a157de4a
8e82462d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 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 @
7d5dce9
...
@@ -449,6 +449,13 @@ BelongsToMany.prototype.injectGetter = function(obj) {
...
@@ -449,6 +449,13 @@ BelongsToMany.prototype.injectGetter = function(obj) {
_
.
assign
(
throughWhere
,
through
.
scope
);
_
.
assign
(
throughWhere
,
through
.
scope
);
}
}
//If a user pass a where on the options through options, make an "and" with the current throughWhere
if
(
options
.
through
&&
options
.
through
.
where
)
{
throughWhere
=
{
$and
:
[
throughWhere
,
options
.
through
.
where
]
};
}
options
.
include
=
options
.
include
||
[];
options
.
include
=
options
.
include
||
[];
options
.
include
.
push
({
options
.
include
.
push
({
association
:
association
.
oneFromTarget
,
association
:
association
.
oneFromTarget
,
...
...
test/integration/associations/belongs-to-many.test.js
View file @
7d5dce9
...
@@ -1643,6 +1643,26 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
...
@@ -1643,6 +1643,26 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
});
});
});
});
});
});
describe
(
'query with through.where'
,
function
()
{
it
(
'should support query the through model'
,
function
()
{
return
this
.
User
.
create
().
then
(
function
(
user
)
{
return
Promise
.
all
([
user
.
createProject
({},
{
status
:
'active'
,
data
:
1
}),
user
.
createProject
({},
{
status
:
'inactive'
,
data
:
2
}),
user
.
createProject
({},
{
status
:
'inactive'
,
data
:
3
})
]).
then
(
function
()
{
return
Promise
.
all
([
user
.
getProjects
({
through
:
{
where
:
{
status
:
'active'
}
}
}),
user
.
countProjects
({
through
:
{
where
:
{
status
:
'inactive'
}
}
}),
]);
});
}).
spread
(
function
(
activeProjects
,
inactiveProjectCount
)
{
expect
(
activeProjects
).
to
.
have
.
lengthOf
(
1
);
expect
(
inactiveProjectCount
).
to
.
eql
(
2
);
});
});
});
});
});
describe
(
'removing from the join table'
,
function
()
{
describe
(
'removing from the join table'
,
function
()
{
...
...
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