Skip to content

Commit

Permalink
Merge pull request #24514 from colemanw/fixWhereEquations
Browse files Browse the repository at this point in the history
SearchKit - Fix arithmetic in WHERE clause
  • Loading branch information
demeritcowboy authored Sep 14, 2022
2 parents 06ddfae + 412da97 commit 40391ad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Civi/Api4/Query/Api4SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public function composeClause(array $clause, string $type, int $depth) {

// For WHERE clause, expr must be the name of a field.
if ($type === 'WHERE' && !$isExpression) {
$expr = $this->getExpression($expr, ['SqlField', 'SqlFunction']);
$expr = $this->getExpression($expr, ['SqlField', 'SqlFunction', 'SqlEquation']);
if ($expr->getType() === 'SqlField') {
$fieldName = count($expr->getFields()) === 1 ? $expr->getFields()[0] : NULL;
$field = $this->getField($fieldName, TRUE);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v4/Action/SqlExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testSelectEquations() {
// This field will be null
'(hold_date + 5) AS null_plus_five',
])
->addWhere('contact_id', '=', $contact['id'])
->addWhere('(contact_id + 1)', '=', 1 + $contact['id'])
->setLimit(1)
->execute()
->first();
Expand Down

0 comments on commit 40391ad

Please sign in to comment.