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

Commit 8cb6df21 by corpix Committed by Sascha Depold

Added global options for define, query, sync

1 parent abdbc324
...@@ -26,6 +26,8 @@ var instanceMethods = { ...@@ -26,6 +26,8 @@ var instanceMethods = {
define: function(modelName, attributes, options) { define: function(modelName, attributes, options) {
options = options || {} options = options || {}
if(this.options.defineOptions) options = Sequelize.Utils.merge(options, this.options.defineOptions)
var model = this.modelManager.addModel(new ModelDefinition(modelName, attributes, options)) var model = this.modelManager.addModel(new ModelDefinition(modelName, attributes, options))
return model return model
...@@ -38,11 +40,18 @@ var instanceMethods = { ...@@ -38,11 +40,18 @@ var instanceMethods = {
query: function(sql, callee, options) { query: function(sql, callee, options) {
options = options || {} options = options || {}
if(this.options.queryOptions) options = Sequelize.Utils.merge(options, this.options.queryOptions)
options.logging = this.options.hasOwnProperty('logging') ? this.options.logging : true options.logging = this.options.hasOwnProperty('logging') ? this.options.logging : true
return new Query(this.config, callee, options).run(sql) return new Query(this.config, callee, options).run(sql)
}, },
sync: function(options) { sync: function(options) {
options = options || {}
if(this.options.syncOptions) options = Sequelize.Utils.merge(options, this.options.syncOptions)
var self = this var self = this
var eventEmitter = new Utils.CustomEventEmitter(function() { var eventEmitter = new Utils.CustomEventEmitter(function() {
var chainer = new Utils.QueryChainer var chainer = new Utils.QueryChainer
...@@ -60,4 +69,4 @@ var instanceMethods = { ...@@ -60,4 +69,4 @@ var instanceMethods = {
Sequelize.Utils._.map(DataTypes, function(sql, accessor) { Sequelize[accessor] = sql}) Sequelize.Utils._.map(DataTypes, function(sql, accessor) { Sequelize[accessor] = sql})
Sequelize.Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct}) Sequelize.Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct})
\ No newline at end of file
...@@ -137,6 +137,12 @@ var Utils = module.exports = { ...@@ -137,6 +137,12 @@ var Utils = module.exports = {
}, },
pluralize: function(s) { pluralize: function(s) {
return Utils.Lingo.en.isPlural(s) ? s : Utils.Lingo.en.pluralize(s) return Utils.Lingo.en.isPlural(s) ? s : Utils.Lingo.en.pluralize(s)
},
merge: function(a, b){
for(var key in b) {
a[key] = b[key]
}
return a
} }
} }
...@@ -153,4 +159,4 @@ CustomEventEmitter.prototype.run = function() { ...@@ -153,4 +159,4 @@ CustomEventEmitter.prototype.run = function() {
} }
Utils.QueryChainer = require("./query-chainer") Utils.QueryChainer = require("./query-chainer")
Utils.Lingo = require("lingo") Utils.Lingo = require("lingo")
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!