^value in table.array query leads to an exception
Closed this issue · 1 comments
ontofractal commented
in
operator doesn't work as expected in the following code:
tag = "elixir"
query = from p in Post, where: ^tag in p.tags, order_by: [desc: p.id]
posts = Repo.all(query)
When run process is terminated with the following exception:
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Enumerable not implemented for {{:., [], [{:&, [], [0]}, :tags]}, [], []}
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:116: Enumerable.reduce/3
(elixir) lib/enum.ex:1776: Enum.map/2
(ecto_mnesia) lib/ecto_mnesia/record/context/match_spec.ex:89: Ecto.Mnesia.Record.Context.MatchSpec.condition_expression/3
(ecto_mnesia) lib/ecto_mnesia/record/context/match_spec.ex:63: Ecto.Mnesia.Record.Context.MatchSpec.match_conditions/4
(ecto_mnesia) lib/ecto_mnesia/record/context/match_spec.ex:19: Ecto.Mnesia.Record.Context.MatchSpec.update/2
(ecto_mnesia) lib/ecto_mnesia/adapter.ex:58: Ecto.Mnesia.Adapter.execute/6
(ecto) lib/ecto/repo/queryable.ex:130: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
...
...
relevant schema part is
field :tags, {:array, :string}
Any advice? Thanks!
AndrewDryga commented
Hello.
Unfortunately this adapter uses MatchSpec
to query fields, and there is no easy way to make "item in field value" queries. I guess it can be done by using QLC
instead of MatchSpec
, but we are not at that point yet.
I will add a raise for this case, to make it clear for developers.
P.S.: Even :in
is emulated by replacing it with multiple :or
statements.