我尝试使用runtime.onMessage
在where子句中执行$in
条件但未成功:
iex(2)> Hookshot.Hook.with_events([1, 2]) |> Hookshot.Repo.all
** (Ecto.Query.CastError) web/models/hook.ex:63: value `[1, 2]` in `where` cannot be cast to type {:in, {:array, :string}} in query:
from h in Hookshot.Hook,
where: h.events in ^[1, 2],
select: h
(elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/repo/queryable.ex:122: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(iex) lib/iex/evaluator.ex:182: IEx.Evaluator.handle_eval/6
(iex) lib/iex/evaluator.ex:175: IEx.Evaluator.do_eval/4
(iex) lib/iex/evaluator.ex:155: IEx.Evaluator.eval/4
模型中的实施:
def with_events(query \\ Hook, events) do
from h in query,
where: h.events in ^events
end
我做错了吗?