Skip to content

Commit 586b6ce

Browse files
authored
test: load aggregate with select and sort on from_many relationship (#661)
This test captures an approach that was previously working, however commit 10fa4c introduced a regression that causes the following error: (Postgrex.Error) ERROR 42703 (undefined_column) column s0.author_id does not exist
1 parent 4f6137c commit 586b6ce

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/aggregate_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,35 @@ defmodule AshSql.AggregateTest do
19761976
end
19771977
end
19781978

1979+
test "load aggregate with select and sort on from_many relationship" do
1980+
author =
1981+
Author
1982+
|> Ash.Changeset.for_create(:create, %{first_name: "John", last_name: "Doe"})
1983+
|> Ash.create!()
1984+
1985+
post =
1986+
Post
1987+
|> Ash.Changeset.for_create(:create, %{title: "Test Post"})
1988+
|> Ash.Changeset.manage_relationship(:author, author, type: :append_and_remove)
1989+
|> Ash.create!()
1990+
1991+
Comment
1992+
|> Ash.Changeset.for_create(:create, %{title: "Test Comment"})
1993+
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
1994+
|> Ash.create!()
1995+
1996+
results =
1997+
Post
1998+
|> Ash.Query.filter(id == ^post.id)
1999+
|> Ash.Query.select([:id, :title])
2000+
|> Ash.Query.sort([{Ash.Sort.expr_sort(expr(latest_comment.created_at)), :desc}])
2001+
|> Ash.Query.load(:author_first_name)
2002+
|> Ash.read!()
2003+
2004+
assert Enum.count(results) == 1
2005+
assert List.first(results).author_first_name == "John"
2006+
end
2007+
19792008
test "aggregate with parent() ref in relationship filter and sorting on relationship field" do
19802009
chat_1 =
19812010
Chat

0 commit comments

Comments
 (0)