Skip to content

Commit

Permalink
fix inspecting dynamc with interpolated named bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Nov 2, 2024
1 parent a54d96f commit d0f51ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ecto/query/inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ defimpl Inspect, for: Ecto.Query.DynamicExpr do
|> Enum.map(&%JoinExpr{ix: &1})

aliases =
for({as, _} when is_atom(as) <- binding, do: as)
Enum.flat_map(binding, fn
{as, _} when is_atom(as) -> [as]
{{:^, _, [as]}, _} when is_atom(as) -> [as]
_ -> []
end)
|> Enum.with_index()
|> Map.new()

Expand Down
3 changes: 3 additions & 0 deletions test/ecto/query/inspect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ defmodule Ecto.Query.InspectTest do
assert inspect(dynamic([comments: c], c.bar == ^1)) ==
"dynamic([comments: c], c.bar == ^1)"

assert inspect(dynamic([{^:comments, c}], c.bar == ^1)) ==
"dynamic([{^:comments, c}], c.bar == ^1)"

dynamic = dynamic([p], p.bar == ^1)

assert inspect(dynamic([p], ^dynamic and p.foo == ^0)) ==
Expand Down

0 comments on commit d0f51ff

Please sign in to comment.