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

Commit d7353be8 by Verdier

Do not inject Model..include in options directly

1 parent dea73751
......@@ -2547,6 +2547,9 @@ Model.$injectScope = function (scope, options) {
}
return sameModel;
})) {
// Do not inject Model.$scope.include directly,
// make a shallow copy (#4470).
scopeInclude = _.clone(scopeInclude);
options.include.push(scopeInclude);
}
});
......
......@@ -26,6 +26,9 @@ describe(Support.getTestDialectTeaser('associations'), function() {
}
});
this.Post.addScope('withComments', {
include: [this.Comment]
});
this.Post.hasMany(this.Comment, {
foreignKey: 'commentable_id',
scope: {
......@@ -141,6 +144,31 @@ describe(Support.getTestDialectTeaser('associations'), function() {
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') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!