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

Commit 458960d7 by Marco Amado Committed by Sushant

fix(separate): don't propagate group to separated queries (#9754)

1 parent f97cac29
......@@ -1828,7 +1828,7 @@ class Model {
return include.association.get(results, _.assign(
{},
_.omit(options, ['include', 'attributes', 'originalAttributes', 'order', 'where', 'limit', 'offset', 'plain']),
_.omit(options, ['include', 'attributes', 'originalAttributes', 'order', 'where', 'limit', 'offset', 'plain', 'group']),
_.omit(include, ['parent', 'association', 'as', 'originalAttributes'])
)).then(map => {
for (const result of results) {
......
......@@ -1422,6 +1422,48 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
expect(User.hasMany.bind(User, User, { as: 'user' })).to
.throw ('Naming collision between attribute \'user\' and association \'user\' on model user. To remedy this, change either foreignKey or as in your association definition');
});
it('should ignore group from ancestor on deep separated query', function() {
const User = this.sequelize.define('user', {
userId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
username: Sequelize.STRING
});
const Task = this.sequelize.define('task', {
taskId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
title: Sequelize.STRING
});
const Job = this.sequelize.define('job', {
jobId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
title: Sequelize.STRING
});
Task.hasMany(Job, { foreignKey: 'taskId' });
User.hasMany(Task, { foreignKey: 'userId' });
return this.sequelize.sync({ force: true })
.then(() => {
return User.create({
username: 'John Doe',
tasks: [
{ title: 'Task #1', jobs: [{ title: 'Job #1' }, { title: 'Job #2' }] },
{ title: 'Task #2', jobs: [{ title: 'Job #3' }, { title: 'Job #4' }] }
]
}, { include: [{ model: Task, include: [Job] }] });
})
.then(() => {
return User.findAndCountAll({
attributes: ['userId'],
include: [
{ model: Task, separate: true, include: [{ model: Job, separate: true }]}
],
group: [['userId']],
});
})
.then(({ count, rows }) => {
expect(count.length).to.equal(1);
expect(rows[0].tasks[0].jobs.length).to.equal(2);
});
});
});
describe('sourceKey', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!