Skip to content

Commit f74a60b

Browse files
committed
test: add test for ash-project/ash_sql#127
1 parent 097509c commit f74a60b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/aggregate_test.exs

+22
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,28 @@ defmodule AshSql.AggregateTest do
10251025
|> Ash.read_one!()
10261026
end
10271027

1028+
@tag :regression
1029+
test "aggregates with parent expressions in their filters are not grouped" do
1030+
post =
1031+
Post
1032+
|> Ash.Changeset.for_create(:create, %{title: "title"})
1033+
|> Ash.create!()
1034+
1035+
Comment
1036+
|> Ash.Changeset.for_create(:create, %{title: "title"})
1037+
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
1038+
|> Ash.create!()
1039+
1040+
Comment
1041+
|> Ash.Changeset.for_create(:create, %{title: "something else"})
1042+
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
1043+
|> Ash.create!()
1044+
1045+
assert %{count_of_comments: 2, count_of_comments_with_same_name: 1} =
1046+
post
1047+
|> Ash.load!([:count_of_comments, :count_of_comments_with_same_name])
1048+
end
1049+
10281050
describe "sum" do
10291051
test "with no related data it returns nil" do
10301052
post =

test/support/resources/post.ex

+5
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ defmodule AshPostgres.Test.Post do
896896
aggregates do
897897
sum(:sum_of_comment_ratings_calc, [:comments, :ratings], :double_score)
898898
count(:count_of_comments, :comments)
899+
900+
count :count_of_comments_with_same_name, :comments do
901+
filter(expr(title == parent(title)))
902+
end
903+
899904
count(:count_of_linked_posts, :linked_posts)
900905

901906
count :count_of_comments_called_match, :comments do

0 commit comments

Comments
 (0)