不要怂,就是干,撸起袖子干!

Commit af8b3053 by Joshua Cullen Committed by Sushant

fix(abstract/querygenerator): Use includeAs as the key for subQueryWhere. (#7918)

1 parent afb396e7
...@@ -1343,7 +1343,7 @@ const QueryGenerator = { ...@@ -1343,7 +1343,7 @@ const QueryGenerator = {
].join(' ')); ].join(' '));
if (_.isPlainObject(topLevelInfo.options.where)) { if (_.isPlainObject(topLevelInfo.options.where)) {
topLevelInfo.options.where['__' + includeAs] = subQueryWhere; topLevelInfo.options.where['__' + includeAs.internalAs] = subQueryWhere;
} else { } else {
topLevelInfo.options.where = { $and: [topLevelInfo.options.where, subQueryWhere] }; topLevelInfo.options.where = { $and: [topLevelInfo.options.where, subQueryWhere] };
} }
......
...@@ -17,6 +17,61 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -17,6 +17,61 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}); });
describe('findAndCountAll', () => { 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() { 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 }), const User = this.sequelize.define('User', { name: DataTypes.STRING(40) }, { paranoid: true }),
SomeConnection = this.sequelize.define('SomeConnection', { SomeConnection = this.sequelize.define('SomeConnection', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!