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

Commit 0d8dad41 by José Moreira

Paranoid on include

1 parent d0f998a0
Showing with 31 additions and 25 deletions
......@@ -1573,39 +1573,45 @@ module.exports = (function() {
// private
var paranoidClause = function(options) {
if (this.options.paranoid === true) {
options = options || {}
options.where = options.where || {}
var paranoidClause = function ( options ) {
if ( ! this.options.paranoid ) return options || {};
var deletedAtCol = this._timestampAttributes.deletedAt
, quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(deletedAtCol)
options = options || {}
options.where = options.where || {}
// Don't overwrite our explicit deletedAt search value if we provide one
if (!!options.where[deletedAtCol]) {
return options
}
var deletedAtCol = this._timestampAttributes.deletedAt
, quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(deletedAtCol)
if(this.name || this.tableName) {
quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(this.name || this.tableName) + '.' + quoteIdentifiedDeletedAtCol
}
// Don't overwrite our explicit deletedAt search value if we provide one
if (!!options.where[deletedAtCol]) {
return options
}
if (typeof options.where === "string") {
options.where += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
}
else if (Array.isArray(options.where)) {
if(this.name || this.tableName) {
quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(this.name || this.tableName) + '.' + quoteIdentifiedDeletedAtCol
}
// Don't overwrite our explicit deletedAt search value if we provide one
if(options.where[0].indexOf(deletedAtCol) !== -1) {
return options
}
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
} else {
options.where[deletedAtCol] = null
if (typeof options.where === "string") {
options.where += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
}
else if (Array.isArray(options.where)) {
// Don't overwrite our explicit deletedAt search value if we provide one
if(options.where[0].indexOf(deletedAtCol) !== -1) {
return options
}
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
} else {
options.where[deletedAtCol] = null
}
return options
// Apply on each include
if ( options.include && options.include.length )
for( var i in options.include )
if( typeof options.include[i] == 'object' )
paranoidClause.call( options.include[i].daoFactory, options.include[i] );
return options;
}
var addOptionalClassMethods = function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!