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

Commit 650a85d3 by ns3777k Committed by Safonov Nikita

fix fields and-or logic

1 parent 878841b0
...@@ -1789,18 +1789,24 @@ var QueryGenerator = { ...@@ -1789,18 +1789,24 @@ var QueryGenerator = {
} }
} }
if (value) { if (value && (value.$or || value.$and)) {
if (value.$or || value.$and) { binding = value.$or ? ' OR ' : ' AND ';
binding = value.$or ? ' OR ' : ' AND '; value = value.$or || value.$and;
value = (value.$or || value.$and).map(function (_value) { if (_.isPlainObject(value)) {
return self.whereItemQuery(key, _value, options); value = _.reduce(value, function (result, _value, key) {
}).filter(function (item) { result.push(_.zipObject([key], [_value]));
return item && item.length; return result;
}); }, []);
return value.length ? '('+value.join(binding)+')' : undefined;
} }
value = value.map(function (_value) {
return self.whereItemQuery(key, _value, options);
}).filter(function (item) {
return item && item.length;
});
return value.length ? '('+value.join(binding)+')' : undefined;
} }
if (_.isPlainObject(value) && fieldType instanceof DataTypes.JSON && options.json !== false) { if (_.isPlainObject(value) && fieldType instanceof DataTypes.JSON && options.json !== false) {
......
...@@ -186,6 +186,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -186,6 +186,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')' default: '([email] = \'maker@mhansen.io\' OR [email] = \'janzeh@gmail.com\')'
}); });
testsql('rank', {
$or: {
$lt: 100,
$eq: null
}
}, {
default: '([rank] < 100 OR [rank] IS NULL)'
});
testsql('$or', [ testsql('$or', [
{email: 'maker@mhansen.io'}, {email: 'maker@mhansen.io'},
{email: 'janzeh@gmail.com'} {email: 'janzeh@gmail.com'}
...@@ -259,6 +268,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -259,6 +268,15 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: "([name] LIKE '%hello' AND [name] LIKE 'hello%')" default: "([name] LIKE '%hello' AND [name] LIKE 'hello%')"
}); });
testsql('rank', {
$and: {
$ne: 15,
$between: [10, 20]
}
}, {
default: '([rank] != 15 AND [rank] BETWEEN 10 AND 20)'
});
testsql('name', { testsql('name', {
$and: [ $and: [
{like : '%someValue1%'}, {like : '%someValue1%'},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!