Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ecto/query/planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ defmodule Ecto.Query.Planner do
distinct: nil,
lock: nil
} ->
join_query = put_in(join_query.aliases[@parent_as], query)

join_query = rewrite_prefix(join_query, query.prefix)
from = rewrite_prefix(join_query.from, prefix)
{from, source} = plan_source(join_query, from, adapter, cte_names)
Expand Down
14 changes: 14 additions & 0 deletions test/ecto/query/planner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,20 @@ defmodule Ecto.Query.PlannerTest do
assert Macro.to_string(hd(hd(query.joins).source.query.wheres).expr) =~ "in %Ecto.SubQuery{"
end

test "normalize: parent_as in subquery wrapped in a query should not raise an error" do
child = from(p in Post,
where: p.status == ^:published,
select: %{field: parent_as(:outer).posted > ^~N[2025-01-01 00:00:00]}
)

query = from thing in Post,
as: :outer,
inner_lateral_join: sub in ^(from row in subquery(child)),
on: true

assert Macro.to_string(normalize(query)) =~ "%{field: parent_as(:outer).posted"
end

test "normalize: assoc join with wheres that have regular filters" do
# Mixing both has_many and many_to_many
{_query, cast_params, dump_params, _select} =
Expand Down
Loading