fix: support not in query expressions

This commit is contained in:
Zach Daniel 2021-05-05 16:05:32 -04:00
parent 95374b1498
commit ae5b67fcdb

View file

@ -67,7 +67,7 @@ defmodule Ash.Query do
} }
alias Ash.Error.SideLoad.{InvalidQuery, NoSuchRelationship} alias Ash.Error.SideLoad.{InvalidQuery, NoSuchRelationship}
alias Ash.Query.{Aggregate, BooleanExpression, Calculation} alias Ash.Query.{Aggregate, BooleanExpression, Calculation, Not}
defimpl Inspect do defimpl Inspect do
import Inspect.Algebra import Inspect.Algebra
@ -482,12 +482,18 @@ defmodule Ash.Query do
end end
defp do_expr({left, _, [{op, _, [right]}]}, escape?) defp do_expr({left, _, [{op, _, [right]}]}, escape?)
when is_atom(op) and op in @operator_symbols and is_atom(left) do when is_atom(op) and op in @operator_symbols and is_atom(left) and left != :not do
args = Enum.map([{left, [], nil}, right], &do_expr(&1, false)) args = Enum.map([{left, [], nil}, right], &do_expr(&1, false))
soft_escape(%Ash.Query.Call{name: op, args: args, operator?: true}, escape?) soft_escape(%Ash.Query.Call{name: op, args: args, operator?: true}, escape?)
end end
defp do_expr({:not, _, [expression]}, escape?) do
expression = do_expr(expression, false)
soft_escape(Not.new(expression), escape?)
end
defp do_expr({op, _, args}, escape?) when is_atom(op) and is_list(args) do defp do_expr({op, _, args}, escape?) when is_atom(op) and is_list(args) do
args = Enum.map(args, &do_expr(&1, false)) args = Enum.map(args, &do_expr(&1, false))