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

Commit 0926dca1 by sdepold

moved finder above count methods + use findAll in all method on ModelFactory

1 parent a57bd01d
Showing with 21 additions and 21 deletions
...@@ -83,27 +83,7 @@ module.exports = (function() { ...@@ -83,27 +83,7 @@ module.exports = (function() {
} }
ModelFactory.prototype.all = function() { ModelFactory.prototype.all = function() {
return this.QueryInterface.select(this, this.tableName) return this.findAll()
}
ModelFactory.prototype.count = function(options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['count(*)', 'count'])
return this.QueryInterface.rawSelect(this.tableName, options, 'count')
}
ModelFactory.prototype.max = function(field, options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['max(' + field + ')', 'max'])
return this.QueryInterface.rawSelect(this.tableName, options, 'max')
}
ModelFactory.prototype.min = function(field, options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['min(' + field + ')', 'min'])
return this.QueryInterface.rawSelect(this.tableName, options, 'min')
} }
ModelFactory.prototype.findAll = function(options) { ModelFactory.prototype.findAll = function(options) {
...@@ -136,6 +116,26 @@ module.exports = (function() { ...@@ -136,6 +116,26 @@ module.exports = (function() {
return this.QueryInterface.select(this, this.tableName, options, {plain: true}) return this.QueryInterface.select(this, this.tableName, options, {plain: true})
} }
ModelFactory.prototype.count = function(options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['count(*)', 'count'])
return this.QueryInterface.rawSelect(this.tableName, options, 'count')
}
ModelFactory.prototype.max = function(field, options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['max(' + field + ')', 'max'])
return this.QueryInterface.rawSelect(this.tableName, options, 'max')
}
ModelFactory.prototype.min = function(field, options) {
options = Utils._.extend({ attributes: [] }, options || {})
options.attributes.push(['min(' + field + ')', 'min'])
return this.QueryInterface.rawSelect(this.tableName, options, 'min')
}
ModelFactory.prototype.build = function(values, options) { ModelFactory.prototype.build = function(values, options) {
var instance = new Model(values, Utils._.extend(this.options, this.attributes, { hasPrimaryKeys: this.hasPrimaryKeys })) var instance = new Model(values, Utils._.extend(this.options, this.attributes, { hasPrimaryKeys: this.hasPrimaryKeys }))
, self = this , self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!