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

Commit 12d4b8cd by Jan Aagaard Meier

bug(scope) Call conform options for scopes that are functions. closes #3991

1 parent a066cbd7
......@@ -3,6 +3,7 @@
- [FEATURE] Added default validation based on attribute types. [#3472](https://github.com/sequelize/sequelize/pull/3472). The validation _cannot_ be disabled. If you really want to completely disable it, you can remove the `validate` function from the corresponding datatype, but know that this permanently disables the validation.
- [FIXED] Fix save to be noop when nothing changed
- [FIXED] Call `conformOptions` on default scope [#4157](https://github.com/sequelize/sequelize/issues/4157)
- [FIXED] Call `conformOptions` on scopes returned by functions [#3991](https://github.com/sequelize/sequelize/issues/3991)
# 3.4.1
- [FIXED] Fix belongs-to-many `countAssociations` - ambigious id when through model has id
......
......@@ -638,12 +638,12 @@ Model.prototype.init = function(modelManager) {
this.$scope = this.options.defaultScope || {};
if (_.isPlainObject(this.$scope) && this.$scope.include) {
if (_.isPlainObject(this.$scope)) {
conformOptions(this.$scope);
}
_.each(this.options.scopes, function (scope) {
if (_.isPlainObject(scope) && scope.include) {
if (_.isPlainObject(scope)) {
conformOptions(scope);
}
});
......@@ -1086,6 +1086,7 @@ Model.prototype.scope = function(option) {
if (_.isFunction(scope)) {
scope = scope();
conformOptions(scope);
}
}
}
......
......@@ -37,8 +37,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
includeActiveProjects: function(){
return {
include: [{
model: sequelize.models.Company,
include: [sequelize.models.Project.scope('active')]
model: sequelize.models.company,
include: [sequelize.models.project.scope('active')]
}]
};
}
......@@ -299,7 +299,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it('should apply scope conditions', function() {
return this.ScopeMe.scope('includeActiveProjects').findById(1).then(function(user) {
return this.ScopeMe.scope('includeActiveProjects').findOne({ where: { id: 1 }}).then(function(user) {
expect(user.company.projects).to.have.length(1);
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!