From 40c2eb74e4cebdaff6895210960aaedf4a26d6dc Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 18 Nov 2025 12:20:59 +0100 Subject: [PATCH 1/3] respect read action sort if relationship does not specify one --- lib/join.ex | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/join.ex b/lib/join.ex index dd626f5..5660206 100644 --- a/lib/join.ex +++ b/lib/join.ex @@ -445,17 +445,24 @@ defmodule AshSql.Join do ) end end) - |> Ash.Query.unset([:sort, :distinct, :select, :limit, :offset]) + |> Ash.Query.unset([:distinct, :select, :limit, :offset]) |> handle_attribute_multitenancy(tenant) |> hydrate_refs(context[:private][:actor]) |> then(fn query -> + # if the relationship has a sort + # unset the sort that may have been added by the read action + # and only use the sort on the relationship if sort? do - Ash.Query.sort(query, relationship.sort) + query + |> Ash.Query.unset(:sort) + |> Ash.Query.sort(relationship.sort) else - Ash.Query.unset(query, :sort) + query end end) + |> Ash.Query.unset([:distinct, :select, :limit, :offset]) |> set_has_parent_expr_context(relationship) + |> Ash.Query.unset([:distinct, :select, :limit, :offset]) |> case do %{valid?: true} = related_query -> parent_bindings = From cb7ddc109148e27d9d8d5b515e9069537d89b561 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Wed, 19 Nov 2025 10:04:31 +0100 Subject: [PATCH 2/3] remove duplicated unsets --- lib/join.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/join.ex b/lib/join.ex index 5660206..ba85edd 100644 --- a/lib/join.ex +++ b/lib/join.ex @@ -460,9 +460,7 @@ defmodule AshSql.Join do query end end) - |> Ash.Query.unset([:distinct, :select, :limit, :offset]) |> set_has_parent_expr_context(relationship) - |> Ash.Query.unset([:distinct, :select, :limit, :offset]) |> case do %{valid?: true} = related_query -> parent_bindings = From 0c13593040f9f5e5ae447806c13e1f7151a83035 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Thu, 20 Nov 2025 07:34:38 +0100 Subject: [PATCH 3/3] fix: only sort in cases where we should sort --- lib/join.ex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/join.ex b/lib/join.ex index ba85edd..14c8de8 100644 --- a/lib/join.ex +++ b/lib/join.ex @@ -449,15 +449,13 @@ defmodule AshSql.Join do |> handle_attribute_multitenancy(tenant) |> hydrate_refs(context[:private][:actor]) |> then(fn query -> - # if the relationship has a sort - # unset the sort that may have been added by the read action - # and only use the sort on the relationship if sort? do query |> Ash.Query.unset(:sort) - |> Ash.Query.sort(relationship.sort) + |> Ash.Query.sort(relationship.sort || query.sort) else query + |> Ash.Query.unset(:sort) end end) |> set_has_parent_expr_context(relationship)