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

Commit 4e941ab0 by Mick Hansen Committed by Jan Aagaard Meier

refactor find & argsArePrimaryKeys a bit

1 parent 54163dc3
Showing with 10 additions and 6 deletions
......@@ -119,21 +119,24 @@ module.exports = (function() {
var start = tk.time();
// no options defined?
// return an emitter which emits null
if([null, undefined].indexOf(options) > -1) {
if([null, undefined].indexOf(options) !== -1) {
return new Utils.CustomEventEmitter(function(emitter) {
setTimeout(function() { emitter.emit('success', null) }, 10)
}).run()
}
var primaryKeys = this.primaryKeys;
// options is not a hash but an id
if(typeof options === 'number') {
options = { where: options }
} else if (Utils.argsArePrimaryKeys(arguments, this.primaryKeys)) {
} else if (!Utils._.isEmpty(primaryKeys) && Utils.argsArePrimaryKeys(arguments, primaryKeys)) {
var where = {}
, self = this
, keys = Utils._.keys(primaryKeys)
Utils._.each(arguments, function(arg, i) {
var key = Utils._.keys(self.primaryKeys)[i]
var key = keys[i]
where[key] = arg
})
......@@ -231,7 +234,7 @@ module.exports = (function() {
DAOFactory.prototype.__defineGetter__('primaryKeys', function() {
var result = {}
Utils._.each(this.attributes, function(dataTypeString, attributeName) {
if((attributeName != 'id') && (dataTypeString.indexOf('PRIMARY KEY') > -1)) {
if((attributeName != 'id') && (dataTypeString.indexOf('PRIMARY KEY') !== -1)) {
result[attributeName] = dataTypeString
}
})
......
......@@ -66,17 +66,18 @@ var Utils = module.exports = {
].join(" ")
},
argsArePrimaryKeys: function(args, primaryKeys) {
return false;
var result = (args.length == Utils._.keys(primaryKeys).length)
if (result) {
Utils._.each(args, function(arg) {
if(result) {
if(['number', 'string'].indexOf(typeof arg) > -1)
if(['number', 'string'].indexOf(typeof arg) !== -1)
result = true
else
result = (arg instanceof Date)
}
})
}
return result
},
combineTableNames: function(tableName1, tableName2) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!