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

Commit cf2b16e8 by Mick Hansen

fix(include): omit properties in findSeperate that messes with how tables are aliases, closes #4605

1 parent d8d639ba
...@@ -1426,7 +1426,7 @@ Model.$findSeparate = function(results, options) { ...@@ -1426,7 +1426,7 @@ Model.$findSeparate = function(results, options) {
return include.association.get(results, _.assign( return include.association.get(results, _.assign(
{}, {},
_.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'plain'), _.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'plain'),
include _.omit(include, 'parent', 'association', 'as')
)).then(function (map) { )).then(function (map) {
results.forEach(function (result) { results.forEach(function (result) {
result.set( result.set(
......
...@@ -231,6 +231,61 @@ if (current.dialect.supports.groupedLimit) { ...@@ -231,6 +231,61 @@ if (current.dialect.supports.groupedLimit) {
}); });
}); });
it('should work having a separate include between a parent and child include', function () {
var User = this.sequelize.define('User', {})
, Project = this.sequelize.define('Project')
, Company = this.sequelize.define('Company')
, Task = this.sequelize.define('Task', {})
, sqlSpy = sinon.spy();
Company.Users = Company.hasMany(User, {as: 'users'});
User.Tasks = User.hasMany(Task, {as: 'tasks'});
Task.Project = Task.belongsTo(Project, {as: 'project'});
return this.sequelize.sync({force: true}).then(function () {
return Promise.join(
Company.create({
id: 1,
users: [
{
tasks: [
{project: {}},
{project: {}},
{project: {}}
]
}
]
}, {
include: [
{association: Company.Users, include: [
{association: User.Tasks, include: [
Task.Project
]}
]}
]
})
).then(function () {
return Company.findAll({
include: [
{association: Company.Users, include: [
{association: User.Tasks, separate: true, include: [
Task.Project
]}
]}
],
order: [
['id', 'ASC']
],
logging: sqlSpy
});
}).then(function (companies) {
expect(sqlSpy).to.have.been.calledTwice;
expect(companies[0].users[0].tasks[0].project).to.be.ok;
});
});
});
it('should run two nested hasMany association in a separate queries', function () { it('should run two nested hasMany association in a separate queries', function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Project = this.sequelize.define('Project', {}) , Project = this.sequelize.define('Project', {})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!