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 af8b3053
authored
Aug 13, 2017
by
Joshua Cullen
Committed by
Sushant
Aug 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(abstract/querygenerator): Use includeAs as the key for subQueryWhere. (#7918)
1 parent
afb396e7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletions
lib/dialects/abstract/query-generator.js
test/integration/include/findAndCountAll.test.js
lib/dialects/abstract/query-generator.js
View file @
af8b305
...
...
@@ -1343,7 +1343,7 @@ const QueryGenerator = {
].
join
(
' '
));
if
(
_
.
isPlainObject
(
topLevelInfo
.
options
.
where
))
{
topLevelInfo
.
options
.
where
[
'__'
+
includeAs
]
=
subQueryWhere
;
topLevelInfo
.
options
.
where
[
'__'
+
includeAs
.
internalAs
]
=
subQueryWhere
;
}
else
{
topLevelInfo
.
options
.
where
=
{
$and
:
[
topLevelInfo
.
options
.
where
,
subQueryWhere
]
};
}
...
...
test/integration/include/findAndCountAll.test.js
View file @
af8b305
...
...
@@ -17,6 +17,61 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
describe
(
'findAndCountAll'
,
()
=>
{
it
(
'should be able to include two required models with a limit. Result rows should match limit.'
,
function
()
{
const
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
},
name
:
DataTypes
.
STRING
(
40
)
}),
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
name
:
DataTypes
.
STRING
(
40
),
fk
:
DataTypes
.
INTEGER
}),
Employee
=
this
.
sequelize
.
define
(
'Employee'
,
{
name
:
DataTypes
.
STRING
(
40
),
fk
:
DataTypes
.
INTEGER
});
Project
.
hasMany
(
Task
,
{
foreignKey
:
'fk'
,
constraints
:
false
});
Project
.
hasMany
(
Employee
,
{
foreignKey
:
'fk'
,
constraints
:
false
});
Task
.
belongsTo
(
Project
,
{
foreignKey
:
'fk'
,
constraints
:
false
});
Employee
.
belongsTo
(
Project
,
{
foreignKey
:
'fk'
,
constraints
:
false
});
// Sync them
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
// Create an enviroment
return
Promise
.
join
(
Project
.
bulkCreate
([
{
id
:
1
,
name
:
'No tasks'
},
{
id
:
2
,
name
:
'No tasks no employees'
},
{
id
:
3
,
name
:
'No employees'
},
{
id
:
4
,
name
:
'In progress A'
},
{
id
:
5
,
name
:
'In progress B'
},
{
id
:
6
,
name
:
'In progress C'
}
]),
Task
.
bulkCreate
([
{
name
:
'Important task'
,
fk
:
3
},
{
name
:
'Important task'
,
fk
:
4
},
{
name
:
'Important task'
,
fk
:
5
},
{
name
:
'Important task'
,
fk
:
6
}
]),
Employee
.
bulkCreate
([
{
name
:
'Jane Doe'
,
fk
:
1
},
{
name
:
'John Doe'
,
fk
:
4
},
{
name
:
'Jane John Doe'
,
fk
:
5
},
{
name
:
'John Jane Doe'
,
fk
:
6
}
])
).
then
(()
=>
{
//Find all projects with tasks and employees
const
availableProjects
=
3
;
const
limit
=
2
;
return
Project
.
findAndCountAll
({
include
:
[{
model
:
Task
,
required
:
true
},
{
model
:
Employee
,
required
:
true
}],
limit
}).
then
(
result
=>
{
expect
(
result
.
count
).
to
.
be
.
equal
(
availableProjects
);
expect
(
result
.
rows
.
length
).
to
.
be
.
equal
(
limit
,
'Complete set of available rows were not returned.'
);
});
});
});
});
it
(
'should be able to include a required model. Result rows should match count'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
}),
SomeConnection
=
this
.
sequelize
.
define
(
'SomeConnection'
,
{
...
...
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