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

Commit 64d13eaf by Mick Hansen

feat/fix(include): provide through.scope support for includes

1 parent cbc54303
......@@ -1001,7 +1001,7 @@ module.exports = (function() {
// Generate a wrapped join so that the through table join can be dependent on the target join
joinQueryItem += joinType + '(';
joinQueryItem += self.quoteTable(throughTable, throughAs);
joinQueryItem += joinType + self.quoteTable(table, as) + ' ON ';
joinQueryItem += ' INNER JOIN ' + self.quoteTable(table, as) + ' ON ';
joinQueryItem += targetJoinOn;
if (throughWhere) {
......
......@@ -2032,6 +2032,11 @@ module.exports = (function() {
_pseudo: true
});
if (through.scope) {
include.through.where = include.through.where ? new Utils.and([include.through.where, through.scope]) : through.scope;
}
include.include.push(include.through);
tableNames[through.tableName] = true;
}
......
......@@ -412,6 +412,37 @@ describe(Support.getTestDialectTeaser('associations'), function() {
expect(questionTags.map(function(tag) {
return tag.name;
}).sort()).to.deep.equal(['questionTag', 'tagA', 'tagC']);
}).then(function () {
return Promise.join(
self.Post.find({
where: {},
include: [self.Tag]
}),
self.Image.find({
where: {},
include: [self.Tag]
}),
self.Question.find({
where: {},
include: [self.Tag]
})
).spread(function (post, image, question) {
expect(post.tags.length).to.equal(3);
expect(image.tags.length).to.equal(3);
expect(question.tags.length).to.equal(3);
expect(post.tags.map(function(tag) {
return tag.name;
}).sort()).to.deep.equal(['postTag', 'tagA', 'tagB']);
expect(image.tags.map(function(tag) {
return tag.name;
}).sort()).to.deep.equal(['imageTag', 'tagB', 'tagC']);
expect(question.tags.map(function(tag) {
return tag.name;
}).sort()).to.deep.equal(['questionTag', 'tagA', 'tagC']);
});
});
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!