Skip to content

Commit

Permalink
Merge pull request #20824 from colemanw/fixUpdateOperators
Browse files Browse the repository at this point in the history
SearchKit - Fix reloading a search with an OR group in the WHERE clause
  • Loading branch information
colemanw authored Jul 11, 2021
2 parents 3efec37 + c5a21c4 commit e23c290
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_.each(ctrl.clauses, updateOperators);
};

// Return a list of operators allowed for the field in a given clause
this.getOperators = function(clause) {
var field = ctrl.getField(clause[0]);
if (!field || !field.operators) {
Expand All @@ -48,8 +49,13 @@
return ctrl.operators[opKey];
};

// Ensures a clause is using an operator that is allowed for the field
function updateOperators(clause) {
if (!ctrl.skip && (!clause[1] || !_.includes(_.pluck(ctrl.getOperators(clause), 'key'), clause[1]))) {
// Recurse into AND/OR/NOT groups
if (ctrl.conjunctions[clause[0]]) {
_.each(clause[1], updateOperators);
}
else if (!ctrl.skip && (!clause[1] || !_.includes(_.pluck(ctrl.getOperators(clause), 'key'), clause[1]))) {
clause[1] = ctrl.getOperators(clause)[0].key;
ctrl.changeClauseOperator(clause);
}
Expand Down

0 comments on commit e23c290

Please sign in to comment.