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

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