From 170afddd853de96d17b7b0d3194636b319612a6c Mon Sep 17 00:00:00 2001 From: Artiom Lunev Date: Tue, 8 Apr 2025 18:07:11 +0100 Subject: [PATCH] fix: ash postgres subquery usage --- lib/data_layer.ex | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index 5cb460f8..c4295a7a 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -1041,12 +1041,16 @@ defmodule AshPostgres.DataLayer do Map.get(relationship, :manual) -> {module, opts} = relationship.manual - module.ash_postgres_subquery( - opts, - 0, - 0, - base_query - ) + case module.ash_postgres_subquery(opts, 0, 0, base_query) do + {:ok, subquery} -> + subquery + + {:error, error} -> + {:error, error} + + subquery -> + subquery + end Map.get(relationship, :no_attributes?) -> base_query @@ -1234,8 +1238,7 @@ defmodule AshPostgres.DataLayer do subquery( from( destination in query, - join: - through in ^through_query, + join: through in ^through_query, as: ^through_binding, on: field(through, ^destination_attribute_on_join_resource) ==