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

Commit 8839629b by Yuri Sulyma

Fixed hashToWhereConditions and arrayValue in QueryGenerator to correctly handle…

… in: and not: in where: conditions (fixes #1079)
1 parent cf7aa753
......@@ -957,12 +957,12 @@ module.exports = (function() {
return joins;
},
arrayValue: function(value, key, _key){
arrayValue: function(value, key, _key, logicResult){
var _value = null;
if (value.length === 0) { value = [null] }
_value = "(" + value.map(function(v) { return this.escape(v) }.bind(this)).join(',') + ")"
return [_key, _value].join(" IN ")
return [_key, _value].join(" " + logicResult + " ")
},
/*
......@@ -995,7 +995,7 @@ module.exports = (function() {
}
if (Array.isArray(value)) {
result.push(this.arrayValue(value, key, _key, dao))
result.push(this.arrayValue(value, key, _key, dao, "IN"))
} else if ((value) && (typeof value == 'object') && !(value instanceof Date) && !Buffer.isBuffer(value)) {
if (!!value.join) {
//using as sentinel for join column => value
......@@ -1004,10 +1004,9 @@ module.exports = (function() {
} else {
for (var logic in value) {
var logicResult = Utils.getWhereLogic(logic, hash[key][logic]);
if (logic === "IN" || logic === "NOT IN") {
var values = Array.isArray(where[i][ii]) ? where[i][ii] : [where[i][ii]]
_where[_where.length] = i + ' ' + logic + ' (' + values.map(function(){ return '?' }).join(',') + ')'
_whereArgs = _whereArgs.concat(values)
if (logicResult === "IN" || logicResult === "NOT IN") {
var values = Array.isArray(value[logic]) ? value[logic] : [value[logic]]
result.push(this.arrayValue(values, key, _key, dao, logicResult))
}
else if (logicResult === "BETWEEN" || logicResult === "NOT BETWEEN") {
_value = this.escape(value[logic][0])
......
......@@ -136,7 +136,7 @@ module.exports = (function() {
attributes: attrString.join(', ') })
},
arrayValue: function(value, key, _key, factory){
arrayValue: function(value, key, _key, factory, logicResult){
var col = null
, coltype = null
, _realKey = key.split('.').pop()
......@@ -157,7 +157,7 @@ module.exports = (function() {
return [_key, _value].join(" && ")
} else {
_value = "(" + value.map(this.escape).join(',') + ")"
return [_key, _value].join(" IN ")
return [_key, _value].join(" " + logicResult + " ")
}
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!