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

Commit 1db2ee6f by Jan Aagaard Meier

bug(scopes) Call conform options on default scope. Closes #4157

1 parent 28ec91a5
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- [FIXED] Fix findOrCreate regression trying to add a transaction even if there is none - [FIXED] Fix findOrCreate regression trying to add a transaction even if there is none
- [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. - [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] Fix save to be noop when nothing changed
- [FIXED] Call `conformOptions` on default scope [#4157](https://github.com/sequelize/sequelize/issues/4157)
# 3.4.1 # 3.4.1
- [FIXED] Fix belongs-to-many `countAssociations` - ambigious id when through model has id - [FIXED] Fix belongs-to-many `countAssociations` - ambigious id when through model has id
......
...@@ -636,7 +636,11 @@ Model.prototype.init = function(modelManager) { ...@@ -636,7 +636,11 @@ Model.prototype.init = function(modelManager) {
// Add head and tail default attributes (id, timestamps) // Add head and tail default attributes (id, timestamps)
addOptionalClassMethods.call(this); addOptionalClassMethods.call(this);
this.$scope = _.isPlainObject(this.options.defaultScope) ? this.options.defaultScope : {}; this.$scope = this.options.defaultScope || {};
if (_.isPlainObject(this.$scope) && this.$scope.include) {
conformOptions(this.$scope);
}
_.each(this.options.scopes, function (scope) { _.each(this.options.scopes, function (scope) {
if (_.isPlainObject(scope) && scope.include) { if (_.isPlainObject(scope) && scope.include) {
......
...@@ -63,6 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -63,6 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
Company = current.define('company', {}, { Company = current.define('company', {}, {
defaultScope: { defaultScope: {
include: [Project],
where: { active: true } where: { active: true }
}, },
scopes: scopes scopes: scopes
...@@ -70,7 +71,10 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -70,7 +71,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('.scope', function () { describe('.scope', function () {
it('should apply default scope', function () { it('should apply default scope', function () {
expect(Company.$scope).to.deep.equal({ where: { active: true }}); expect(Company.$scope).to.deep.equal({
include: [{ model: Project }],
where: { active: true }
});
}); });
it('should be able to unscope', function () { it('should be able to unscope', function () {
...@@ -125,6 +129,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -125,6 +129,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('should be able to combine default with another scope', function () { it('should be able to combine default with another scope', function () {
expect(Company.scope(['defaultScope', {method: ['actualValue', 11]}]).$scope).to.deep.equal({ expect(Company.scope(['defaultScope', {method: ['actualValue', 11]}]).$scope).to.deep.equal({
include: [{ model: Project }],
where: { where: {
active: true, active: true,
other_value: 11 other_value: 11
...@@ -140,6 +145,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -140,6 +145,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it('should override the default scope', function () { it('should override the default scope', function () {
expect(Company.scope(['defaultScope', {method: ['complexFunction', 'qux']}]).$scope).to.deep.equal({ expect(Company.scope(['defaultScope', {method: ['complexFunction', 'qux']}]).$scope).to.deep.equal({
include: [{ model: Project }],
where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ] where: [ 'qux IN (SELECT foobar FROM some_sql_function(foo.bar))' ]
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!