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 3481577c
authored
Apr 21, 2014
by
Terry Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a test case for including models when retrieving objects through association
1 parent
705b7014
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
test/include.test.js
test/include.test.js
View file @
3481577
...
...
@@ -623,6 +623,52 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
it
(
'should support include when retrieving associated objects'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{
name
:
DataTypes
.
STRING
})
,
Group
=
this
.
sequelize
.
define
(
'group'
,
{
name
:
DataTypes
.
STRING
})
,
UserGroup
=
this
.
sequelize
.
define
(
'user_group'
,
{
vip
:
DataTypes
.
INTEGER
})
User
.
hasMany
(
Group
)
Group
.
belongsTo
(
User
)
User
.
hasMany
(
Group
,
{
through
:
UserGroup
,
as
:
'Clubs'
})
Group
.
hasMany
(
User
,
{
through
:
UserGroup
,
as
:
'Members'
})
this
.
sequelize
.
sync
().
success
(
function
()
{
User
.
create
({
name
:
'Owner'
}).
success
(
function
(
owner
)
{
User
.
create
({
name
:
'Member'
}).
success
(
function
(
member
)
{
Group
.
create
({
name
:
'Group'
}).
success
(
function
(
group
)
{
owner
.
addGroup
(
group
).
success
(
function
()
{
group
.
addMember
(
member
).
success
(
function
()
{
owner
.
getGroups
({
include
:
[{
model
:
User
,
as
:
'Members'
}]
}).
success
(
function
(
groups
)
{
expect
(
groups
.
length
).
to
.
equal
(
1
)
expect
(
groups
[
0
].
members
[
0
].
name
).
to
.
equal
(
'Member'
)
done
()
})
})
})
})
})
})
})
})
})
describe
(
'where'
,
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