improvement: distinct on source of query, not relationship destination

This commit is contained in:
Zach Daniel 2022-12-15 17:16:53 -05:00
parent 1c4bec5bc7
commit bfefef7fd5
2 changed files with 15 additions and 1 deletions

View file

@ -313,7 +313,7 @@ defmodule AshPostgres.Join do
joined_query
else
from(row in joined_query,
distinct: ^Ash.Resource.Info.primary_key(relationship.destination)
distinct: ^Ash.Resource.Info.primary_key(joined_query.__ash_bindings__.resource)
)
end
else

View file

@ -159,6 +159,20 @@ defmodule AshPostgres.SortTest do
|> Ash.Query.sort(title: :desc)
|> Ash.Query.filter(linked_posts.title in ["aaa", "bbb", "ccc"] or title == "aaa")
)
assert [
%{title: "ccc"},
%{title: "bbb"},
%{title: "aaa"}
] =
Api.read!(
Post
|> Ash.Query.sort(title: :desc)
|> Ash.Query.filter(
linked_posts.title in ["aaa", "bbb", "ccc"] or
post_links.source_post_id == ^post2.id
)
)
end
test "calculations can be sorted on w/o loading aggregates they reference" do