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

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,7 +235,8 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -235,7 +235,8 @@ 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', {})
...@@ -243,42 +244,57 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -243,42 +244,57 @@ describe(Support.getTestDialectTeaser("Include"), function () {
, SubCategory = this.sequelize.define('SubCategory', {}) , SubCategory = this.sequelize.define('SubCategory', {})
, Capital = this.sequelize.define('Capital', {}); , Capital = this.sequelize.define('Capital', {});
Capital.hasMany(Category, { foreignKey: 'boundCapital'}) User.hasOne(SubscriptionForm, {foreignKey:'boundUser'});
SubCategory.belongsTo(Category, {foreignKey: 'boundCategory'}) SubscriptionForm.belongsTo(User, {foreignKey:'boundUser'});
Category.belongsTo(Capital, {foreignKey:'boundCapital'})
Category.hasMany(SubCategory, {foreignKey:'boundCategory'}) SubscriptionForm.hasOne(Collection, {foreignKey:'boundDesigner'});
Category.hasMany(SubscriptionForm, {foreignKey:'boundCategory'}) Collection.belongsTo(SubscriptionForm, {foreignKey:'boundDesigner'});
Collection.belongsTo(SubscriptionForm, {foreignKey:'boundDesigner'})
SubscriptionForm.belongsTo(User, {foreignKey:'boundUser'}) SubscriptionForm.belongsTo(Category, {foreignKey:'boundCategory'});
SubscriptionForm.belongsTo(Category, {foreignKey:'boundCategory'}) Category.hasMany(SubscriptionForm, {foreignKey:'boundCategory'});
SubscriptionForm.hasOne(Collection, {foreignKey:'boundDesigner'})
User.hasOne(SubscriptionForm, {foreignKey:'boundUser'}) Capital.hasMany(Category, { foreignKey: 'boundCapital'});
Category.belongsTo(Capital, {foreignKey:'boundCapital'});
return this.sequelize.sync({force: true})
.then(function() { Category.hasMany(SubCategory, {foreignKey:'boundCategory'});
SubCategory.belongsTo(Category, {foreignKey: 'boundCategory'});
return this.sequelize.sync({force: true}).then(function() {
return User.find({ return User.find({
include: [{ include: [
{
model: SubscriptionForm, model: SubscriptionForm,
include: [{ include: [
{
model: Collection, model: Collection,
where: { where: {
id: 0 id: 13
} }
}, { },
{
model: Category, model: Category,
include: [{ include: [
{
model: SubCategory model: SubCategory
}, { },
{
model: Capital, model: Capital,
include: [{ include: [
{
model: Category 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!