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 af6723bb
authored
Jun 26, 2015
by
David Langer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add failing test case for findAndCountAll with a include and where
1 parent
c38aa5f7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
test/integration/include/findAndCountAll.test.js
test/integration/include/findAndCountAll.test.js
View file @
af6723b
...
...
@@ -180,5 +180,43 @@ describe(Support.getTestDialectTeaser('Include'), function() {
expect
(
result
.
rows
.
length
).
to
.
equal
(
2
);
});
});
it
.
only
(
'should return the correct count and rows when using a required belongsTo with a where condition and a limit'
,
function
()
{
var
s
=
this
.
sequelize
,
Foo
=
s
.
define
(
'Foo'
,
{})
,
Bar
=
s
.
define
(
'Bar'
,
{
m
:
DataTypes
.
STRING
(
40
)});
Foo
.
hasMany
(
Bar
);
Bar
.
belongsTo
(
Foo
);
return
s
.
sync
({
force
:
true
}).
then
(
function
()
{
// Make five instances of Foo
return
Foo
.
bulkCreate
([{
id
:
1
},
{
id
:
2
},
{
id
:
3
},
{
id
:
4
},
{
id
:
5
}]);
}).
then
(
function
()
{
// Make four instances of Bar, related to the last four instances of Foo
return
Bar
.
bulkCreate
([{
'FooId'
:
1
,
m
:
'yes'
},
{
'FooId'
:
1
,
m
:
'yes'
},
{
'FooId'
:
1
,
m
:
'no'
},
{
'FooId'
:
2
,
m
:
'yes'
}]);
}).
then
(
function
()
{
// Query for the first instance of Foo which have related Bars with m === 'yes'
return
Foo
.
findAndCountAll
({
include
:
[{
model
:
Bar
,
required
:
true
,
where
:
{
m
:
'yes'
}
}],
limit
:
1
}).
tap
(
function
()
{
// Check for what should be returned as the `count` of the result
return
Foo
.
findAll
({
include
:
[{
model
:
Bar
,
required
:
true
,
where
:
{
m
:
'yes'
}
}]
}).
then
(
function
(
items
)
{
expect
(
items
.
length
).
to
.
equal
(
2
);
});
});
}).
then
(
function
(
result
)
{
// There should be 2 instances matching the query (Instances 1 and 2),
// see the findAll statement
expect
(
result
.
count
).
to
.
equal
(
2
);
// The first one of those should be returned due to the limit (Foo
// instance 1)
expect
(
result
.
rows
.
length
).
to
.
equal
(
1
);
});
});
});
});
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