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

Commit 028f656a by JacobLey Committed by GitHub

fix(include): separate queries are not sub-queries (#12152)

1 parent a2c0a631
......@@ -548,7 +548,7 @@ class Model {
include.subQuery = false;
} else {
include.subQueryFilter = false;
include.subQuery = include.subQuery || include.hasParentRequired && include.hasRequired;
include.subQuery = include.subQuery || include.hasParentRequired && include.hasRequired && !include.separate;
}
}
......
......@@ -494,6 +494,53 @@ if (current.dialect.supports.groupedLimit) {
});
});
});
it('should work with required non-separate parent and required child', function() {
const User = this.sequelize.define('User', {});
const Task = this.sequelize.define('Task', {});
const Company = this.sequelize.define('Company', {});
Task.User = Task.belongsTo(User);
User.Tasks = User.hasMany(Task);
User.Company = User.belongsTo(Company);
return this.sequelize.sync({ force: true }).then(() => {
return Task.create({ id: 1 }).then(task => {
return task.createUser({ id: 2 });
}).then(user => {
return user.createCompany({ id: 3 });
}).then(() => {
return Task.findAll({
include: [{
association: Task.User,
required: true,
include: [{
association: User.Tasks,
attributes: ['UserId'],
separate: true,
include: [{
association: Task.User,
attributes: ['id'],
required: true,
include: [{
association: User.Company
}]
}]
}]
}]
});
}).then(results => {
expect(results.length).to.equal(1);
expect(results[0].id).to.equal(1);
expect(results[0].User.id).to.equal(2);
expect(results[0].User.Tasks.length).to.equal(1);
expect(results[0].User.Tasks[0].User.id).to.equal(2);
expect(results[0].User.Tasks[0].User.Company.id).to.equal(3);
});
});
});
});
});
}
......@@ -405,6 +405,26 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(options.include[0].subQueryFilter).to.equal(false);
});
it('should not tag a separate hasMany association with subQuery true', function() {
const options = Sequelize.Model._validateIncludedElements({
model: this.Company,
include: [
{
association: this.Company.Employees,
separate: true,
include: [
{ association: this.User.Tasks, required: true }
]
}
],
required: true
});
expect(options.subQuery).to.equal(false);
expect(options.include[0].subQuery).to.equal(false);
expect(options.include[0].subQueryFilter).to.equal(false);
});
it('should tag a hasMany association with where', function() {
const options = Sequelize.Model._validateIncludedElements({
model: this.User,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!