From 8976ab6722d4a1a077a243f9c5fe8aa9234bcd04 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 9 Jan 2024 08:31:06 -0500 Subject: [PATCH] improvement: use the target action when generating related queries --- lib/join.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/join.ex b/lib/join.ex index 3a41c96c..e3c8cc4f 100644 --- a/lib/join.ex +++ b/lib/join.ex @@ -208,11 +208,21 @@ defmodule AshPostgres.Join do is_subquery? \\ true, join_relationships? \\ false ) do + read_action = + relationship.read_action || + Ash.Resource.Info.primary_action!(relationship.destination, :read).name + + context = (bindings || root_query.__ash_bindings__).context + resource |> Ash.Query.new(nil, base_filter?: false) |> Ash.Query.set_context(%{data_layer: %{start_bindings_at: start_binding}}) - |> Ash.Query.set_context((bindings || root_query.__ash_bindings__).context) + |> Ash.Query.set_context(context) |> Ash.Query.set_context(relationship.context) + |> Ash.Query.for_read(read_action, %{}, + actor: context[:private][:actor], + tenant: context[:private][:tenant] + ) |> case do %{valid?: true} = query -> ash_query = query