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

Commit 1c7db237 by Mick Hansen

Merge branch 'ekmartin-nested_include_where'

2 parents 7c5cb57b 791b44d5
......@@ -954,7 +954,7 @@ module.exports = (function() {
joinOn =
// Left side
(
(subQuery && !include.subQuery && include.parent.subQuery && !(include.hasParentRequired && include.hasParentWhere)) && self.quoteIdentifier(tableLeft + '.' + attrLeft) ||
(subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired || include.hasParentWhere)) && self.quoteIdentifier(tableLeft + '.' + attrLeft) ||
self.quoteTable(tableLeft) + '.' + self.quoteIdentifier(attrLeft)
)
......@@ -962,7 +962,7 @@ module.exports = (function() {
// Right side
(
(subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired && include.hasParentWhere)) && self.quoteIdentifier(tableRight + '.' + attrRight) ||
(subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired || include.hasParentWhere)) && self.quoteIdentifier(tableRight + '.' + attrRight) ||
self.quoteTable(tableRight) + '.' + self.quoteIdentifier(attrRight)
);
......
......@@ -116,6 +116,47 @@ describe(Support.getTestDialectTeaser("Include"), function () {
});
});
it('should support a nested include (with a where)', function() {
var A = this.sequelize.define('A', {
name: DataTypes.STRING
});
var B = this.sequelize.define('B', {
flag: DataTypes.BOOLEAN
});
var C = this.sequelize.define('C', {
name: DataTypes.STRING
});
A.hasOne(B);
B.belongsTo(A);
B.hasMany(C);
C.belongsTo(B);
return this.sequelize
.sync({ force: true })
.then(function () {
return A.find({
include: [
{
model: B,
where: { flag: true },
include: [
{
model: C
}
]
}
]
})
})
.then(function (a) {
expect(a).to.not.exist;
});
});
it('should support many levels of belongsTo (with a lower level having a where)', function (done) {
var A = this.sequelize.define('a', {})
, B = this.sequelize.define('b', {})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!