Skip to content

Commit

Permalink
fix: handle double select issue
Browse files Browse the repository at this point in the history
chore: update for 1.18
  • Loading branch information
zachdaniel committed Dec 19, 2024
1 parent 056979c commit d2657c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 27.0.1
elixir 1.18.0-rc.0-otp-27
elixir 1.18.0-otp-27
11 changes: 7 additions & 4 deletions lib/data_layer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ defmodule AshPostgres.DataLayer do
data_layer_query =
data_layer_query
|> Ecto.Query.exclude(:distinct)
|> Ecto.Query.exclude(:select)

if query.__ash_bindings__[:__order__?] do
{:ok,
Expand Down Expand Up @@ -1149,10 +1150,12 @@ defmodule AshPostgres.DataLayer do

case lateral_join_source_query(query, source_query) do
{:ok, data_layer_query} ->
data_layer_query = Ecto.Query.exclude(data_layer_query, :select)

through_resource
|> Ash.Query.new()
|> Ash.Query.put_context(:data_layer, %{
start_bindings_at: data_layer_query.__ash_bindings__.current
start_bindings_at: Map.get(data_layer_query, :__ash_bindings__)[:current]
})
|> Ash.Query.set_context(through_relationship.context)
|> Ash.Query.do_filter(through_relationship.filter)
Expand All @@ -1168,6 +1171,7 @@ defmodule AshPostgres.DataLayer do
end
|> case do
{:ok, through_query} ->
through_query = Ecto.Query.exclude(through_query, :select)
if query.__ash_bindings__[:__order__?] do
subquery =
subquery(
Expand All @@ -1180,7 +1184,7 @@ defmodule AshPostgres.DataLayer do
source_query,
relationship.through
),
as: ^data_layer_query.__ash_bindings__.current,
as: ^Map.get(data_layer_query, :__ash_bindings__)[:current],
on:
field(through, ^destination_attribute_on_join_resource) ==
field(destination, ^destination_attribute),
Expand All @@ -1197,7 +1201,6 @@ defmodule AshPostgres.DataLayer do
)
)

data_layer_query = Ecto.Query.exclude(data_layer_query, :distinct)

{:ok,
from(source in data_layer_query,
Expand All @@ -1220,7 +1223,7 @@ defmodule AshPostgres.DataLayer do
source_query,
relationship.through
),
as: ^data_layer_query.__ash_bindings__.current,
as: ^Map.get(data_layer_query, :__ash_bindings__)[:current],
on:
field(through, ^destination_attribute_on_join_resource) ==
field(destination, ^destination_attribute),
Expand Down

0 comments on commit d2657c1

Please sign in to comment.