Invalid select values from query

incorrect:

project_ids =
  from(p in Project,
    where: p.id in ^["42", "43"],
    where: p.owner_id == ^current_user.id,
    select: p.id
  ) |> Repo.all()

IO.inspect project_ids // '*+' instead of [42, 43]

Correct:

project_ids =
  from(p in Project,
    where: p.id in ^["1", "19"],
    where: p.owner_id == ^current_user.id,
    select: p.id
  ) |> Repo.all()

IO.inspect project_ids // [1,19] -> correct

magic ? what is it ? ascii, how can i convert it ? why it happened ?

You have been bitten by charlist… ‘*+’ == [42, 43]

iex> [42, 43]
'*+'
iex> [1,19]
[1, 19]

how can I do what I want ?)

It is exactly the same… but You can inspect with charlists option

iex> inspect [42, 43]                      
"'*+'"
iex> inspect [42, 43], charlists: :as_lists 
"[42, 43]"

How can I use them in Enum.map ?

Use it as normal… it’s just the representation that hurts You.

1 Like

congrats, you have reached charlist level of elixir… we have all been there.

iex> list = [42,43]
'*+'
iex> Enum.map(list, fn item -> IO.inspect(item) end)
42
43
4 Likes