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

Commit a728a7aa by Jan Aagaard Meier

Fix default scope being overwritten. Closes #2087

1 parent aaf80ff9
...@@ -9,6 +9,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -9,6 +9,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Hid `dottie.transform` on raw queries behind a flag (`nest`) [#2064](https://github.com/sequelize/sequelize/pull/2064) - [BUG] Hid `dottie.transform` on raw queries behind a flag (`nest`) [#2064](https://github.com/sequelize/sequelize/pull/2064)
- [BUG] Fixed problems with transcation parameter being removed / not passed on in associations [#1789](https://github.com/sequelize/sequelize/issues/1789) and [#1968](https://github.com/sequelize/sequelize/issues/1968) - [BUG] Fixed problems with transcation parameter being removed / not passed on in associations [#1789](https://github.com/sequelize/sequelize/issues/1789) and [#1968](https://github.com/sequelize/sequelize/issues/1968)
- [BUG] Fix problem with minConnections. [#2048](https://github.com/sequelize/sequelize/issues/2048) - [BUG] Fix problem with minConnections. [#2048](https://github.com/sequelize/sequelize/issues/2048)
- [BUG] Fix default scope being overwritten [#2087](https://github.com/sequelize/sequelize/issues/2087)
- [INTERNALS] Replaced lingo with inflection - [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils` - [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
- [INTERNALS] Update dependencies - [INTERNALS] Update dependencies
......
...@@ -497,6 +497,8 @@ module.exports = (function() { ...@@ -497,6 +497,8 @@ module.exports = (function() {
, argLength = arguments.length , argLength = arguments.length
, lastArg = arguments[argLength - 1]; , lastArg = arguments[argLength - 1];
self.scoped = true;
// Set defaults // Set defaults
scopeOptions = (typeof lastArg === 'object' && !Array.isArray(lastArg) ? lastArg : {}) || {}; // <-- for no arguments scopeOptions = (typeof lastArg === 'object' && !Array.isArray(lastArg) ? lastArg : {}) || {}; // <-- for no arguments
scopeOptions.silent = (scopeOptions !== null && scopeOptions.hasOwnProperty('silent') ? scopeOptions.silent : true); scopeOptions.silent = (scopeOptions !== null && scopeOptions.hasOwnProperty('silent') ? scopeOptions.silent : true);
......
...@@ -554,18 +554,18 @@ module.exports = (function() { ...@@ -554,18 +554,18 @@ module.exports = (function() {
return this.sequelize.query(sql, null, options); return this.sequelize.query(sql, null, options);
}; };
QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) { QueryInterface.prototype.select = function(model, tableName, options, queryOptions) {
options = options || {}; options = options || {};
// See if we need to merge options and factory.scopeObj // See if we need to merge options and model.scopeObj
// we're doing this on the QueryInterface level because it's a bridge between // we're doing this on the QueryInterface level because it's a bridge between
// sequelize and the databases // sequelize and the databases
if (Object.keys(factory.scopeObj).length > 0) { if (model.options.defaultScope && Object.keys(model.options.defaultScope).length > 0) {
if (!!options) { if (!!options) {
Utils.injectScope.call(factory, options, true); Utils.injectScope.call(model, options, true);
} }
var scopeObj = buildScope.call(factory); var scopeObj = buildScope.call(model);
Object.keys(scopeObj).forEach(function(method) { Object.keys(scopeObj).forEach(function(method) {
if (typeof scopeObj[method] === 'number' || !Utils._.isEmpty(scopeObj[method])) { if (typeof scopeObj[method] === 'number' || !Utils._.isEmpty(scopeObj[method])) {
options[method] = scopeObj[method]; options[method] = scopeObj[method];
...@@ -575,7 +575,7 @@ module.exports = (function() { ...@@ -575,7 +575,7 @@ module.exports = (function() {
options.lock = queryOptions.lock; options.lock = queryOptions.lock;
var sql = this.QueryGenerator.selectQuery(tableName, options, factory); var sql = this.QueryGenerator.selectQuery(tableName, options, model);
queryOptions = Utils._.extend({}, queryOptions, { queryOptions = Utils._.extend({}, queryOptions, {
include: options.include, include: options.include,
includeNames: options.includeNames, includeNames: options.includeNames,
...@@ -586,7 +586,7 @@ module.exports = (function() { ...@@ -586,7 +586,7 @@ module.exports = (function() {
originalAttributes: options.originalAttributes originalAttributes: options.originalAttributes
}); });
return this.sequelize.query(sql, factory, queryOptions); return this.sequelize.query(sql, model, queryOptions);
}; };
QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) { QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) {
......
...@@ -82,7 +82,15 @@ var Utils = module.exports = { ...@@ -82,7 +82,15 @@ var Utils = module.exports = {
var self = this; var self = this;
scope = scope || {}; scope = scope || {};
self.scopeObj = self.scopeObj || {};
if (!this.scoped && self.options.defaultScope) {
self.scopeObj = Utils._.clone(self.options.defaultScope);
if (!Array.isArray(self.scopeObj.where)) {
self.scopeObj.where = [self.scopeObj.where];
}
} else {
self.scopeObj = self.scopeObj || {};
}
if (Array.isArray(scope.where)) { if (Array.isArray(scope.where)) {
self.scopeObj.where = self.scopeObj.where || []; self.scopeObj.where = self.scopeObj.where || [];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!