Skip to content

Commit

Permalink
fix: properly add filters for exists aggregates
Browse files Browse the repository at this point in the history
closes: #173
  • Loading branch information
zachdaniel committed Nov 17, 2023
1 parent cef3d20 commit 33bd0a7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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__
)

Expand Down

0 comments on commit 33bd0a7

Please sign in to comment.