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

Commit 56a8bb47 by Mick Hansen

fix(include): cover yet another complex nested include case

1 parent b7610eab
...@@ -1011,7 +1011,7 @@ module.exports = (function() { ...@@ -1011,7 +1011,7 @@ module.exports = (function() {
// Filter statement // Filter statement
// Used by both join and subquery where // Used by both join and subquery where
if (subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired || include.hasParentWhere)) { if (subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired || include.hasParentWhere || include.parent.hasIncludeRequired || include.parent.hasIncludeWhere)) {
joinOn = self.quoteIdentifier(tableLeft + '.' + attrLeft); joinOn = self.quoteIdentifier(tableLeft + '.' + attrLeft);
} else { } else {
if (association.associationType !== 'BelongsTo') { if (association.associationType !== 'BelongsTo') {
......
...@@ -235,50 +235,66 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -235,50 +235,66 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}) })
} }
}); });
it('should work on pretty complicated case', function () {
it('should work on a nested set of relations with a where condition in between relations', function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, SubscriptionForm = this.sequelize.define('SubscriptionForm', {}) , SubscriptionForm = this.sequelize.define('SubscriptionForm', {})
, Collection = this.sequelize.define('Collection', {}) , Collection = this.sequelize.define('Collection', {})
, Category= this.sequelize.define('Category', {}) , Category= this.sequelize.define('Category', {})
, SubCategory = this.sequelize.define('SubCategory', {}) , SubCategory = this.sequelize.define('SubCategory', {})
, Capital = this.sequelize.define('Capital', {}); , Capital = this.sequelize.define('Capital', {});
User.hasOne(SubscriptionForm, {foreignKey:'boundUser'});
SubscriptionForm.belongsTo(User, {foreignKey:'boundUser'});
SubscriptionForm.hasOne(Collection, {foreignKey:'boundDesigner'});
Collection.belongsTo(SubscriptionForm, {foreignKey:'boundDesigner'});
SubscriptionForm.belongsTo(Category, {foreignKey:'boundCategory'});
Category.hasMany(SubscriptionForm, {foreignKey:'boundCategory'});
Capital.hasMany(Category, { foreignKey: 'boundCapital'}) Capital.hasMany(Category, { foreignKey: 'boundCapital'});
SubCategory.belongsTo(Category, {foreignKey: 'boundCategory'}) Category.belongsTo(Capital, {foreignKey:'boundCapital'});
Category.belongsTo(Capital, {foreignKey:'boundCapital'})
Category.hasMany(SubCategory, {foreignKey:'boundCategory'}) Category.hasMany(SubCategory, {foreignKey:'boundCategory'});
Category.hasMany(SubscriptionForm, {foreignKey:'boundCategory'}) SubCategory.belongsTo(Category, {foreignKey: 'boundCategory'});
Collection.belongsTo(SubscriptionForm, {foreignKey:'boundDesigner'})
SubscriptionForm.belongsTo(User, {foreignKey:'boundUser'})
SubscriptionForm.belongsTo(Category, {foreignKey:'boundCategory'}) return this.sequelize.sync({force: true}).then(function() {
SubscriptionForm.hasOne(Collection, {foreignKey:'boundDesigner'})
User.hasOne(SubscriptionForm, {foreignKey:'boundUser'})
return this.sequelize.sync({force: true})
.then(function() {
return User.find({ return User.find({
include: [{ include: [
model: SubscriptionForm, {
include: [{ model: SubscriptionForm,
model: Collection, include: [
where: { {
id: 0 model: Collection,
} where: {
}, { id: 13
model: Category, }
include: [{ },
model: SubCategory {
}, { model: Category,
model: Capital, include: [
include: [{ {
model: Category model: SubCategory
}] },
}] {
}] model: Capital,
}] include: [
}) {
}) model: Category
}
]
}
]
}
]
}
]
});
});
}); });
it('should accept nested `where` and `limit` at the same time', function () { it('should accept nested `where` and `limit` at the same time', function () {
var Product = this.sequelize.define('Product', { var Product = this.sequelize.define('Product', {
title: DataTypes.STRING title: DataTypes.STRING
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!