From b4ec957651896e85328988df0a081bebdd2b074b Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 26 Jul 2023 18:50:58 -0400 Subject: [PATCH] improvement: handle `no_attributes?` better in more places --- lib/data_layer.ex | 15 +++++++++++---- lib/expr.ex | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index ecb3d3b..b6ac582 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -906,7 +906,6 @@ defmodule AshPostgres.DataLayer do root_data, [{source_query, source_attribute, destination_attribute, relationship}] ) do - source_values = Enum.map(root_data, &Map.get(&1, source_attribute)) source_query = Ash.Query.new(source_query) base_query = @@ -959,13 +958,22 @@ defmodule AshPostgres.DataLayer do end |> case do {:ok, data_layer_query} -> + data_layer_query = + if Map.get(relationship, :no_attributes?) do + data_layer_query + else + source_values = Enum.map(root_data, &Map.get(&1, source_attribute)) + + from(source in data_layer_query, + where: field(source, ^source_attribute) in ^source_values + ) + end + if query.__ash_bindings__[:__order__?] do {:ok, from(source in data_layer_query, - where: field(source, ^source_attribute) in ^source_values, inner_lateral_join: destination in ^subquery, on: true, - order_by: destination.__order__, select: destination, select_merge: %{__lateral_join_source__: field(source, ^source_attribute)}, distinct: true @@ -973,7 +981,6 @@ defmodule AshPostgres.DataLayer do else {:ok, from(source in data_layer_query, - where: field(source, ^source_attribute) in ^source_values, inner_lateral_join: destination in ^subquery, on: true, select: destination, diff --git a/lib/expr.ex b/lib/expr.ex index 9a9b00b..e2b5569 100644 --- a/lib/expr.ex +++ b/lib/expr.ex @@ -1180,6 +1180,9 @@ defmodule AshPostgres.Expr do field(through, ^first_relationship.source_attribute_on_join_resource) ) + Map.get(first_relationship, :no_attributes?) -> + filtered + true -> source_ref = ref_binding(