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

Commit 88a8a941 by Jan Aagaard Meier

bug(scopes) Fix defaultScope being inherited from parent to through model. Closes #4300

1 parent b17f57ac
...@@ -292,7 +292,7 @@ Mixin.belongsToMany = function(targetModel, options) { // testhint options:none ...@@ -292,7 +292,7 @@ Mixin.belongsToMany = function(targetModel, options) { // testhint options:none
options.hooks = options.hooks === undefined ? false : Boolean(options.hooks); options.hooks = options.hooks === undefined ? false : Boolean(options.hooks);
options.useHooks = options.hooks; options.useHooks = options.hooks;
options.timestamps = options.timestamps === undefined ? this.sequelize.options.timestamps : options.timestamps; options.timestamps = options.timestamps === undefined ? this.sequelize.options.timestamps : options.timestamps;
options = _.extend(options, _.omit(sourceModel.options, ['hooks', 'timestamps'])); options = _.extend(options, _.omit(sourceModel.options, ['hooks', 'timestamps', 'scopes', 'defaultScope']));
// the id is in the foreign table or in a connecting table // the id is in the foreign table or in a connecting table
var association = new BelongsToMany(sourceModel, targetModel, options); var association = new BelongsToMany(sourceModel, targetModel, options);
......
...@@ -14,6 +14,32 @@ var chai = require('chai') ...@@ -14,6 +14,32 @@ var chai = require('chai')
, Promise = current.Promise; , Promise = current.Promise;
describe(Support.getTestDialectTeaser('belongsToMany'), function() { describe(Support.getTestDialectTeaser('belongsToMany'), function() {
it('should not inherit scopes from parent to join table', function () {
var A = current.define('a')
, B = current.define('b', {}, {
defaultScope: {
where: {
foo: 'bar'
}
},
scopes: {
baz: {
where: {
fooz: 'zab'
}
}
}
})
, AB;
B.belongsToMany(A, { through: 'AB' });
AB = current.model('AB');
expect(AB.options.defaultScope).not.to.be.ok;
expect(AB.options.scopes).to.have.length(0);
});
describe('timestamps', function () { describe('timestamps', function () {
it('follows the global timestamps true option', function () { it('follows the global timestamps true option', function () {
var User = current.define('User', {}) var User = current.define('User', {})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!