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

Commit aaa8f942 by Jan Aagaard Meier

refactor/bug(scopes). Moved initialization of scopes later in model init process…

…. Closes #4735, Closes #4925
1 parent 4768e3c4
......@@ -3,6 +3,7 @@
- [FIXED] `describeTable` maintains proper enum casing in mysql [#5321](https://github.com/sequelize/sequelize/pull/5321)
- [FIXED] Parsing of dates in MySQL, when a named timezone is used [#4208](https://github.com/sequelize/sequelize/issues/4208)
- [FIXED] Truncating in Postgres, when table has a schema [#4306](https://github.com/sequelize/sequelize/issues/4306)
- [FIXED] Moved initialization of scopes later in the model init process. Fixes attribute exclusion in scopes, [#4735](https://github.com/sequelize/sequelize/issues/4735) and [#4925](https://github.com/sequelize/sequelize/issues/4925)
# 3.19.0
- [ADDED] Geography support for postgres
......
......@@ -692,18 +692,6 @@ Model.prototype.init = function(modelManager) {
// Add head and tail default attributes (id, timestamps)
addOptionalClassMethods.call(this);
this.$scope = this.options.defaultScope;
if (_.isPlainObject(this.$scope)) {
conformOptions(this.$scope, this);
}
_.each(this.options.scopes, function (scope) {
if (_.isPlainObject(scope)) {
conformOptions(scope, this);
}
}.bind(this));
// Instance prototype
this.Instance = function() {
Instance.apply(this, arguments);
......@@ -728,6 +716,18 @@ Model.prototype.init = function(modelManager) {
findAutoIncrementField.call(this);
this.$scope = this.options.defaultScope;
if (_.isPlainObject(this.$scope)) {
conformOptions(this.$scope, this);
}
_.each(this.options.scopes, function (scope) {
if (_.isPlainObject(scope)) {
conformOptions(scope, this);
}
}.bind(this));
this.Instance.prototype.$Model =
this.Instance.prototype.Model = this;
......
......@@ -4,6 +4,7 @@
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, current = Support.sequelize;
describe(Support.getTestDialectTeaser('Model'), function() {
......@@ -70,7 +71,45 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
describe('.scope', function () {
it('defaultScope should be an empty object if not overriden', function () {
describe('attribute exclude / include', function () {
var User = current.define('user', {
password: DataTypes.STRING,
name: DataTypes.STRING
}, {
defaultScope: {
attributes: {
exclude: ['password']
}
},
scopes: {
aScope: {
attributes: {
exclude: ['password']
}
}
}
});
it('should be able to exclude in defaultScope #4735', function () {
expect(User.$scope.attributes).to.deep.equal([
'id',
'name',
'createdAt',
'updatedAt'
]);
});
it('should be able to exclude in a scope #4925', function () {
expect(User.scope('aScope').$scope.attributes).to.deep.equal([
'id',
'name',
'createdAt',
'updatedAt'
]);
});
});
it('defaultScope should be an empty object if not overridden', function () {
var Foo = current.define('foo', {}, {});
expect(Foo.scope('defaultScope').$scope).to.deep.equal({});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!