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

Commit a1926bd7 by Mick Hansen

fix(include): simplify join logic a bit so source is always on the left

1 parent 6bf2a1df
......@@ -933,12 +933,12 @@ module.exports = (function() {
}
}
} else {
var left = association.associationType === 'BelongsTo' ? association.target : association.source
var left = association.source
, primaryKeysLeft = left.primaryKeyAttributes
, tableLeft = association.associationType === 'BelongsTo' ? as : parentTable
, attrLeft = primaryKeysLeft[0]
, tableRight = association.associationType === 'BelongsTo' ? parentTable : as
, attrRight = association.identifierField || association.identifier
, tableLeft = parentTable
, attrLeft = association.associationType === 'BelongsTo' ? association.identifierField || association.identifier : primaryKeysLeft[0]
, tableRight = as
, attrRight = association.associationType !== 'BelongsTo' ? association.identifierField || association.identifier : primaryKeysLeft[0]
, joinOn;
// Alias the left attribute if the left attribute is not from a subqueried main table
......@@ -962,7 +962,6 @@ module.exports = (function() {
// Right side
(
(subQuery && !include.subQuery && include.parent.subQuery && (include.hasParentRequired || include.hasParentWhere)) && self.quoteIdentifier(tableRight + '.' + attrRight) ||
self.quoteTable(tableRight) + '.' + self.quoteIdentifier(attrRight)
);
......
......@@ -957,11 +957,16 @@ describe(Support.getTestDialectTeaser("Include"), function () {
// Test
User.find({
where: { username: 'John'},
include: [
{ model: Address, include: [
{ model: Street }
], required: true, where: { active: true } }
]
include: [{
model: Address,
required: true,
where: {
active: true
},
include: [{
model: Street
}]
}]
}).done(function (err, john) {
expect(err).not.to.be.ok
expect(john.Address).to.be.ok
......@@ -1023,7 +1028,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
chainer.run().done(callback)
}]
}, function (err) {
}, function (err) {
expect(err).not.to.be.ok
User.findAll({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!