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

Commit 7a45d6db by Daniel Durante

Cleaned u code and where leakage/pollution should no longer occur.

1 parent 43152a2a
...@@ -30,7 +30,7 @@ module.exports = (function() { ...@@ -30,7 +30,7 @@ module.exports = (function() {
} else { } else {
Utils._.each(options.where, function(value, index) { Utils._.each(options.where, function(value, index) {
delete options.where[index]; delete options.where[index];
smart = Utils.smartWhere(value || [], self.__factory.target.daoFactoryManager.sequelize.options.dialect) smart = Utils.smartWhere(value, self.__factory.target.daoFactoryManager.sequelize.options.dialect)
smart = Utils.compileSmartWhere.call(self.__factory.target, smart) smart = Utils.compileSmartWhere.call(self.__factory.target, smart)
if (smart.length > 0) { if (smart.length > 0) {
value = smart value = smart
...@@ -39,16 +39,10 @@ module.exports = (function() { ...@@ -39,16 +39,10 @@ module.exports = (function() {
options.where[self.__factory.target.tableName+"."+index] = value; options.where[self.__factory.target.tableName+"."+index] = value;
}); });
Utils._.extend(options.where, where) options.where = Utils._.extend(options.where, where)
} }
} else { } else {
smart = Utils.smartWhere(where, self.__factory.target.daoFactoryManager.sequelize.options.dialect) options.where = where;
smart = Utils.compileSmartWhere.call(self.__factory.target, smart, self.__factory.target.daoFactoryManager.sequelize.options.dialect)
if (smart.length > 0) {
options.where = smart
} else {
options.where = where;
}
} }
self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, options) self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, options)
......
...@@ -11,14 +11,15 @@ module.exports = (function() { ...@@ -11,14 +11,15 @@ module.exports = (function() {
options = options || {} options = options || {}
where[this.__factory.identifier] = this.instance.id where[this.__factory.identifier] = this.instance.id
options.where = options.where ? Utils._.extend(options.where, where) : where
if (options.where) { if (options.where) {
smart = Utils.smartWhere(options.where || [], this.__factory.target.daoFactoryManager.sequelize.options.dialect) smart = Utils.smartWhere([where, options.where], this.__factory.target.daoFactoryManager.sequelize.options.dialect)
smart = Utils.compileSmartWhere.call(this.__factory.target, smart) smart = Utils.compileSmartWhere.call(this.__factory.target, smart)
if (smart.length > 0) { if (smart.length > 0) {
options.where = smart options.where = smart
} }
} else {
options.where = where
} }
return this.__factory.target.all(options) return this.__factory.target.all(options)
......
...@@ -118,7 +118,6 @@ var Utils = module.exports = { ...@@ -118,7 +118,6 @@ var Utils = module.exports = {
_where[i].joined[_where[i].joined.length] = where[i][ii] _where[i].joined[_where[i].joined.length] = where[i][ii]
break break
default: default:
console.log('LOG', logic)
_where[i].lazy = _where[i].lazy || {conditions: [], bindings: []} _where[i].lazy = _where[i].lazy || {conditions: [], bindings: []}
_where[i].lazy.conditions[_where[i].lazy.conditions.length] = logic + ' ?' _where[i].lazy.conditions[_where[i].lazy.conditions.length] = logic + ' ?'
_where[i].lazy.bindings = _where[i].lazy.bindings.concat(where[i][ii]) _where[i].lazy.bindings = _where[i].lazy.bindings.concat(where[i][ii])
......
...@@ -230,7 +230,7 @@ describe(Helpers.getTestDialectTeaser("HasMany"), function() { ...@@ -230,7 +230,7 @@ describe(Helpers.getTestDialectTeaser("HasMany"), function() {
chainer.run().success(function(results, article, label1, label2) { chainer.run().success(function(results, article, label1, label2) {
article.setLabels([label1, label2]).success(function() { article.setLabels([label1, label2]).success(function() {
article.getLabels({where: ['until > ?', moment('2014-01-01').toDate()]}).success(function(labels) { article.getLabels({where: ['until > ?', moment('2014-01-02').toDate()]}).success(function(labels) {
expect(labels).toBeArray() expect(labels).toBeArray()
expect(labels.length).toEqual(1) expect(labels.length).toEqual(1)
expect(labels[0].text).toEqual('Epicness') expect(labels[0].text).toEqual('Epicness')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!