mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +12:00
improvement: distinct on source of query, not relationship destination
This commit is contained in:
parent
1c4bec5bc7
commit
bfefef7fd5
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue