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 dade8dae
authored
Feb 21, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2 new test cases for includes with required and limiting
1 parent
cc02a9bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
2 deletions
test/include/findAll.test.js
test/include/findAll.test.js
View file @
dade8da
...
...
@@ -780,13 +780,17 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
it
(
'should be possible to define a belongsTo include as required with limit'
,
function
(
done
)
{
it
(
'should be possible to define a belongsTo include as required with
child hasMany with
limit'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
name
:
DataTypes
.
STRING
})
,
Category
=
this
.
sequelize
.
define
(
'Category'
,
{
category
:
DataTypes
.
STRING
})
User
.
belongsTo
(
Group
)
Group
.
hasMany
(
Category
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
async
.
auto
({
...
...
@@ -803,18 +807,104 @@ describe(Support.getTestDialectTeaser("Include"), function () {
User
.
findAll
().
done
(
callback
)
})
},
categories
:
function
(
callback
)
{
Category
.
bulkCreate
([{},
{}]).
done
(
function
()
{
Category
.
findAll
().
done
(
callback
)
})
},
userGroups
:
[
'users'
,
'groups'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
()
chainer
.
add
(
results
.
users
[
0
].
setGroup
(
results
.
groups
[
1
]))
chainer
.
add
(
results
.
users
[
1
].
setGroup
(
results
.
groups
[
0
]))
chainer
.
run
().
done
(
callback
)
}],
groupCategories
:
[
'groups'
,
'categories'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
()
results
.
groups
.
forEach
(
function
(
group
)
{
chainer
.
add
(
group
.
setCategories
(
results
.
categories
))
})
chainer
.
run
().
done
(
callback
)
}]
},
function
(
err
,
results
)
{
expect
(
err
).
not
.
to
.
be
.
ok
User
.
findAll
({
include
:
[
{
model
:
Group
,
required
:
true
}
{
model
:
Group
,
required
:
true
,
include
:
[
{
model
:
Category
}
]}
],
limit
:
1
}).
done
(
function
(
err
,
users
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
users
.
length
).
to
.
equal
(
1
)
users
.
forEach
(
function
(
user
)
{
expect
(
user
.
group
).
to
.
be
.
ok
expect
(
user
.
group
.
categories
).
to
.
be
.
ok
})
done
()
})
})
})
})
it
(
'should be possible to define a belongsTo include as required with child hasMany which is not required with limit'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'Group'
,
{
name
:
DataTypes
.
STRING
})
,
Category
=
this
.
sequelize
.
define
(
'Category'
,
{
category
:
DataTypes
.
STRING
})
User
.
belongsTo
(
Group
)
Group
.
hasMany
(
Category
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
async
.
auto
({
groups
:
function
(
callback
)
{
Group
.
bulkCreate
([
{
name
:
'A'
},
{
name
:
'B'
}
]).
done
(
function
()
{
Group
.
findAll
().
done
(
callback
)
})
},
users
:
function
(
callback
)
{
User
.
bulkCreate
([{},
{}]).
done
(
function
()
{
User
.
findAll
().
done
(
callback
)
})
},
categories
:
function
(
callback
)
{
Category
.
bulkCreate
([{},
{}]).
done
(
function
()
{
Category
.
findAll
().
done
(
callback
)
})
},
userGroups
:
[
'users'
,
'groups'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
()
chainer
.
add
(
results
.
users
[
0
].
setGroup
(
results
.
groups
[
1
]))
chainer
.
add
(
results
.
users
[
1
].
setGroup
(
results
.
groups
[
0
]))
chainer
.
run
().
done
(
callback
)
}],
groupCategories
:
[
'groups'
,
'categories'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
()
results
.
groups
.
forEach
(
function
(
group
)
{
chainer
.
add
(
group
.
setCategories
(
results
.
categories
))
})
chainer
.
run
().
done
(
callback
)
}]
},
function
(
err
,
results
)
{
expect
(
err
).
not
.
to
.
be
.
ok
User
.
findAll
({
include
:
[
{
model
:
Group
,
required
:
true
,
include
:
[
{
model
:
Category
,
required
:
false
}
]}
],
limit
:
1
}).
done
(
function
(
err
,
users
)
{
...
...
@@ -822,6 +912,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
expect
(
users
.
length
).
to
.
equal
(
1
)
users
.
forEach
(
function
(
user
)
{
expect
(
user
.
group
).
to
.
be
.
ok
expect
(
user
.
group
.
categories
).
to
.
be
.
ok
})
done
()
})
...
...
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