Skip to content

Commit 20a8631

Browse files
committed
test: add tests for fix in ash_sql
1 parent 1ec8d82 commit 20a8631

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/aggregate_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ defmodule AshSql.AggregateTest do
6565
assert read_post.count_of_comments == 1
6666
end
6767

68+
test "nested filters on aggregates works" do
69+
org =
70+
Organization
71+
|> Ash.Changeset.for_create(:create, %{name: "match"})
72+
|> Ash.create!()
73+
74+
post =
75+
Post
76+
|> Ash.Changeset.for_create(:create, %{title: "match"})
77+
|> Ash.Changeset.manage_relationship(:organization, org, type: :append_and_remove)
78+
|> Ash.create!()
79+
80+
post2 =
81+
Post
82+
|> Ash.Changeset.for_create(:create, %{title: "match"})
83+
|> Ash.create!()
84+
85+
Comment
86+
|> Ash.Changeset.for_create(:create, %{title: "match"})
87+
|> Ash.Changeset.manage_relationship(:post, post2, type: :append_and_remove)
88+
|> Ash.create!()
89+
90+
assert [%{count_of_comments_matching_org_name: 1}] =
91+
Post
92+
|> Ash.Query.load(:count_of_comments_matching_org_name)
93+
|> Ash.Query.filter(id == ^post.id)
94+
|> Ash.read!()
95+
end
96+
6897
describe "Context Multitenancy" do
6998
alias AshPostgres.MultitenancyTest.{Org, Post, User}
7099

test/support/resources/post.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,13 @@ defmodule AshPostgres.Test.Post do
850850
filter(title: "match")
851851
end
852852

853+
count :count_of_comments_matching_org_name, [
854+
:posts_with_matching_title,
855+
:comments
856+
] do
857+
filter(expr(parent(organization.name) == title))
858+
end
859+
853860
count(:count_of_comments_containing_title, :comments_containing_title)
854861

855862
first :first_comment, :comments, :title do

0 commit comments

Comments
 (0)