diff --git a/Civi/Api4/Query/Api4SelectQuery.php b/Civi/Api4/Query/Api4SelectQuery.php index 1181029118f6..f4abb51acc1d 100644 --- a/Civi/Api4/Query/Api4SelectQuery.php +++ b/Civi/Api4/Query/Api4SelectQuery.php @@ -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); diff --git a/tests/phpunit/api/v4/Action/SqlExpressionTest.php b/tests/phpunit/api/v4/Action/SqlExpressionTest.php index 745000d39227..f56f833550d0 100644 --- a/tests/phpunit/api/v4/Action/SqlExpressionTest.php +++ b/tests/phpunit/api/v4/Action/SqlExpressionTest.php @@ -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();