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

Commit 99ee1b77 by Mick Hansen

Merge pull request #4500 from Verdier/fix-scope-flat

Do not inject Model.$scope.include in options directly. Fix #4470.
2 parents dea73751 d7353be8
...@@ -2547,6 +2547,9 @@ Model.$injectScope = function (scope, options) { ...@@ -2547,6 +2547,9 @@ Model.$injectScope = function (scope, options) {
} }
return sameModel; return sameModel;
})) { })) {
// Do not inject Model.$scope.include directly,
// make a shallow copy (#4470).
scopeInclude = _.clone(scopeInclude);
options.include.push(scopeInclude); options.include.push(scopeInclude);
} }
}); });
......
...@@ -26,6 +26,9 @@ describe(Support.getTestDialectTeaser('associations'), function() { ...@@ -26,6 +26,9 @@ describe(Support.getTestDialectTeaser('associations'), function() {
} }
}); });
this.Post.addScope('withComments', {
include: [this.Comment]
});
this.Post.hasMany(this.Comment, { this.Post.hasMany(this.Comment, {
foreignKey: 'commentable_id', foreignKey: 'commentable_id',
scope: { scope: {
...@@ -141,6 +144,31 @@ describe(Support.getTestDialectTeaser('associations'), function() { ...@@ -141,6 +144,31 @@ describe(Support.getTestDialectTeaser('associations'), function() {
expect(question.comments[0].get('title')).to.equal('I am a question comment'); expect(question.comments[0].get('title')).to.equal('I am a question comment');
}); });
}); });
it('should make the same query if called multiple time (#4470)', function () {
var self = this;
var logs = [];
var logging = function (log) {
logs.push(log);
};
return this.sequelize.sync({force: true}).then(function () {
return self.Post.create();
}).then(function (post) {
return post.createComment({
title: 'I am a post comment'
});
}).then(function() {
return self.Post.scope('withComments').findAll({
logging: logging
});
}).then(function () {
return self.Post.scope('withComments').findAll({
logging: logging
});
}).then(function () {
expect(logs[0]).to.equal(logs[1]);
});
});
}); });
if (Support.getTestDialect() !== 'sqlite') { if (Support.getTestDialect() !== 'sqlite') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!