fixed build of where statement when filter contains non-existing column
This commit is contained in:
parent
26712a7014
commit
eba7e68059
24
lib/sql.js
24
lib/sql.js
|
@ -754,9 +754,11 @@ SQLConnector.prototype._buildWhere = function(model, where) {
|
|||
if (Array.isArray(clauses)) {
|
||||
for (var i = 0, n = clauses.length; i < n; i++) {
|
||||
var stmtForClause = self._buildWhere(model, clauses[i]);
|
||||
stmtForClause.sql = '(' + stmtForClause.sql + ')';
|
||||
branchParams = branchParams.concat(stmtForClause.params);
|
||||
branches.push(stmtForClause.sql);
|
||||
if (stmtForClause.sql) {
|
||||
stmtForClause.sql = '(' + stmtForClause.sql + ')';
|
||||
branchParams = branchParams.concat(stmtForClause.params);
|
||||
branches.push(stmtForClause.sql);
|
||||
}
|
||||
}
|
||||
stmt.merge({
|
||||
sql: branches.join(' ' + key.toUpperCase() + ' '),
|
||||
|
@ -767,6 +769,12 @@ SQLConnector.prototype._buildWhere = function(model, where) {
|
|||
}
|
||||
// The value is not an array, fall back to regular fields
|
||||
}
|
||||
var p = props[key];
|
||||
if (p == null) {
|
||||
// Unknown property, ignore it
|
||||
debug('Unknown property %s is skipped for model %s', key, model);
|
||||
continue;
|
||||
}
|
||||
var columnName = self.columnEscaped(model, key);
|
||||
var expression = where[key];
|
||||
var columnValue;
|
||||
|
@ -782,10 +790,10 @@ SQLConnector.prototype._buildWhere = function(model, where) {
|
|||
if (Array.isArray(expression)) {
|
||||
// Column value is a list
|
||||
for (var j = 0, m = expression.length; j < m; j++) {
|
||||
columnValue.push(this.toColumnValue(props[key], expression[j]));
|
||||
columnValue.push(this.toColumnValue(p, expression[j]));
|
||||
}
|
||||
} else {
|
||||
columnValue.push(this.toColumnValue(props[key], expression));
|
||||
columnValue.push(this.toColumnValue(p, expression));
|
||||
}
|
||||
if (operator === 'between') {
|
||||
// BETWEEN v1 AND v2
|
||||
|
@ -807,14 +815,14 @@ SQLConnector.prototype._buildWhere = function(model, where) {
|
|||
// do not coerce RegExp based on property definitions
|
||||
columnValue = expression;
|
||||
} else {
|
||||
columnValue = this.toColumnValue(props[key], expression);
|
||||
columnValue = this.toColumnValue(p, expression);
|
||||
}
|
||||
sqlExp = self.buildExpression(
|
||||
columnName, operator, columnValue, props[key]);
|
||||
columnName, operator, columnValue, p);
|
||||
stmt.merge(sqlExp);
|
||||
} else {
|
||||
// The expression is the field value, not a condition
|
||||
columnValue = self.toColumnValue(props[key], expression);
|
||||
columnValue = self.toColumnValue(p, expression);
|
||||
if (columnValue === null) {
|
||||
stmt.merge(columnName + ' IS NULL');
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue