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

Commit cec519bf by Mick Hansen

Merge pull request #1241 from yuri0/master

Fixed hashToWhereConditions and arrayValue in QueryGenerator to correctly handle in: and not: in where: conditions (fixes #1079)
2 parents 6b5472cb b0c3e46f
......@@ -1066,12 +1066,12 @@ module.exports = (function() {
return joins;
},
arrayValue: function(value, key, _key){
arrayValue: function(value, key, _key, factory, 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 + " ")
},
/*
......@@ -1104,7 +1104,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
......@@ -1113,10 +1113,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])
......
......@@ -156,7 +156,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()
......@@ -177,7 +177,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 + " ")
}
},
......
......@@ -906,6 +906,14 @@ if (dialect.match(/^postgres/)) {
arguments: [{ id: [] }],
expectation: "\"id\" IN (NULL)"
},
{
arguments: [{id: {not: [1, 2, 3] }}],
expectation: "\"id\" NOT IN (1,2,3)"
},
{
arguments: [{id: {not: [] }}],
expectation: "\"id\" NOT IN (NULL)"
},
// Variants when quoteIdentifiers is false
{
......@@ -918,6 +926,16 @@ if (dialect.match(/^postgres/)) {
expectation: "id IN (NULL)",
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{ id: {not: [1,2,3] }}],
expectation: "id NOT IN (1,2,3)",
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{ id: {not: [] }}],
expectation: "id NOT IN (NULL)",
context: {options: {quoteIdentifiers: false}}
}
]
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!