From 33bd0a7061c91f9e36d54158164dff064a542dde Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 17 Nov 2023 07:46:43 -0500 Subject: [PATCH] fix: properly add filters for exists aggregates closes: #173 --- lib/aggregate.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/aggregate.ex b/lib/aggregate.ex index d090a56..2d86592 100644 --- a/lib/aggregate.ex +++ b/lib/aggregate.ex @@ -94,10 +94,17 @@ defmodule AshPostgres.Aggregate do is_single? && Enum.at(aggregates, 0).kind == :exists -> [aggregate] = aggregates + expr = + if is_nil(Map.get(aggregate.query, :filter)) do + true + else + Map.get(aggregate.query, :filter) + end + exists = AshPostgres.Expr.dynamic_expr( query, - %Ash.Query.Exists{path: aggregate.relationship_path, expr: true}, + %Ash.Query.Exists{path: aggregate.relationship_path, expr: expr}, query.__ash_bindings__ )