Error Controller (Applying "Where")

Folks,
I have a little doubt …
I’m trying to get my controller to list the content only what is his.

I got the id of the current session, and put it in my “where” to list.

But I get the following error.

Error

value 2 in where cannot be cast to type :string in query:

controller

  def index(conn, params) do
    indicacoes = Dashboards.list_indicacoes()
        sessao_atual = conn.assigns.current_user.id
    page = Indicacao
        |> where([a], a.dev_id == ^sessao_atual)
        |> order_by(desc: :updated_at)
        |> Repo.paginate(params)

    render(conn, "index.html", indicacoes: indicacoes, indicacoes: page.entries, page: page)
  end

Someone would know how to help me, how would it look?

Replace

With

sessao_atual = to_string(conn.assigns.current_user.id)

However, you may want to change the type of your dev_id column to integer, add a foreign key, and use a relationship instead. Then for the code, you’d write:

page = 
  conn.assigns.current_user
  |> assoc(:indicacao)
  |> order_by(desc: :updated_at)
  |> Repo.paginate(params)
3 Likes

that was it
Thanks a lot for the help.