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

Commit 16d3d716 by Mick Hansen

fix(): Fix regression with arrays and objects with multiple keys. closes #3107

1 parent 8108099e
# Next # Next
- [BUG] Fixed regression with `DataTypes.ARRAY(DataTypes.STRING(length))` #3106 - [BUG] Fixed regression with `DataTypes.ARRAY(DataTypes.STRING(length))` #3106
- [BUG] Fixed regression where `.or([{key: value}, {key: value, key2: value}])` would result in 3 `A OR B OR C` rather than `A OR (B AND C)` #3107
# 2.0.1 # 2.0.1
- [BUG] Fixed issue with empty `include.where` - [BUG] Fixed issue with empty `include.where`
......
...@@ -1660,7 +1660,9 @@ module.exports = (function() { ...@@ -1660,7 +1660,9 @@ module.exports = (function() {
if (Array.isArray(value)) { if (Array.isArray(value)) {
value = value.map(function (item) { value = value.map(function (item) {
return self.whereItemsQuery(item, options, binding); var itemQuery = self.whereItemsQuery(item, options, ' AND ');
if (Object.keys(item).length > 1) itemQuery = '('+itemQuery+')';
return itemQuery;
}).filter(function (item) { }).filter(function (item) {
return item && item.length; return item && item.length;
}); });
......
...@@ -170,6 +170,17 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -170,6 +170,17 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: '([equipment] IN (1, 3) OR [muscles] IN (2, 4))' default: '([equipment] IN (1, 3) OR [muscles] IN (2, 4))'
}); });
testsql('$or', [
{
roleName: 'NEW'
}, {
roleName: 'CLIENT',
type: 'CLIENT'
}
], {
default: "([roleName] = 'NEW' OR ([roleName] = 'CLIENT' AND [type] = 'CLIENT'))"
});
test("sequelize.or({group_id: 1}, {user_id: 2})", function () { test("sequelize.or({group_id: 1}, {user_id: 2})", function () {
expectsql(sql.whereItemQuery(undefined, this.sequelize.or({group_id: 1}, {user_id: 2})), { expectsql(sql.whereItemQuery(undefined, this.sequelize.or({group_id: 1}, {user_id: 2})), {
default: "([group_id] = 1 OR [user_id] = 2)" default: "([group_id] = 1 OR [user_id] = 2)"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!