Skip to content

Commit

Permalink
inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Feb 24, 2024
1 parent e1ef5cb commit afa4369
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ecto/query/inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ defimpl Inspect, for: Ecto.Query do
binding_to_expr(ix, names, part)
end

# Format field/2 with string name
defp postwalk({{:., _, [{_, _, _} = binding, field]}, meta, []}, _names, _part)
when is_binary(field) do
{:field, meta, [binding, field]}
end

# Remove parens from field calls
defp postwalk({{:., _, [_, _]} = dot, meta, []}, _names, _part) do
{dot, [no_parens: true] ++ meta, []}
Expand Down
5 changes: 5 additions & 0 deletions test/ecto/query/inspect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ defmodule Ecto.Query.InspectTest do
assert i(plan(query)) == "from v0 in values (#{fields})"
end

test "field/2 with string name" do
query = from p in Post, select: field(p, "visit")
assert i(query) == ~s<from p0 in Inspect.Post, select: field(p0, "visit")>
end

def plan(query) do
{query, _, _} = Ecto.Adapter.Queryable.plan_query(:all, Ecto.TestAdapter, query)
query
Expand Down

0 comments on commit afa4369

Please sign in to comment.