Search code examples
elixirecto

Ecto CastError: value in `join` cannot be cast to type {:in, :string}


I had a list defined like so:

flags = ['flag_a', 'flag_b']

And a query set up something like this:

from(u in User,
     left_join: f in Flags,
     on: f.account_id == u.account_id and f.name in ^@flags

Which gave me this error message:

(Ecto.Query.CastError) lib/service/users.ex:106: value `['flag_a', 'flag_b']` in `join` cannot be cast to type {:in, :string} in query:

... etc ...

Solution

  • I just needed to use double-quotes for the values:

    flags = ["flag_a", "flag_b"]
    

    So that the values in the list were strings and not char lists.