Skip to content

Commit

Permalink
Plan sources before creating plan_subquery closure (#4548)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Nov 12, 2024
1 parent 8054c22 commit f489c96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ecto/query/planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ defmodule Ecto.Query.Planner do
{planned_query :: Ecto.Query.t(), parameters :: list(), cache_key :: any()}
def plan(query, operation, adapter, cte_names \\ %{}) do
{query, cte_names} = plan_ctes(query, adapter, cte_names)
query = plan_sources(query, adapter, cte_names)
plan_subquery = &plan_subquery(&1, query, nil, adapter, false, cte_names)

query
|> plan_sources(adapter, cte_names)
|> plan_assocs()
|> plan_combinations(adapter, cte_names)
|> plan_expr_subqueries(:wheres, plan_subquery)
Expand Down
6 changes: 6 additions & 0 deletions test/ecto/query/subquery_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ defmodule Ecto.Query.SubqueryTest do
assert dump_params == ["foo"]
end

test "in query with exists" do
c = from(c in "comments", where: ^"title" == parent_as(:p).title, select: 1)
s = from(p in "posts", as: :p, where: exists(c), select: count())
normalize(s)
end

test "in dynamic" do
c = from(c in Comment, where: c.text == ^"foo", select: c.post_id)
d = dynamic([p], p.id in subquery(c))
Expand Down

0 comments on commit f489c96

Please sign in to comment.