# Error Controller (Applying "Where")

**URL:** <https://forum.elixirforum.com/t/error-controller-applying-where/21476>\
**Category:** Questions\
**Tags:** ecto, phoenix\
**Created:** [April 8, 2019, 2:24am UTC](https://forum.elixirforum.com/t/error-controller-applying-where/21476 "2019-04-08T02:24:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [April 8, 2019, 2:24am UTC](https://forum.elixirforum.com/t/error-controller-applying-where/21476/1 "2019-04-08T02:24:39Z")

</div>

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

```elixir
  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?

---

<div class="post-metadata">

**Author:** ![blatyo](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/32/4554_2.png) [@blatyo](https://forum.elixirforum.com/u/blatyo)\
**Post date:** [April 8, 2019, 4:00am UTC](https://forum.elixirforum.com/t/error-controller-applying-where/21476/2 "2019-04-08T04:00:07Z")

</div>

Replace

> [@gilbertosj](#):
>
> sessao\_atual = conn.assigns.current\_user.id

With

```elixir
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:

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

```

---

<div class="post-metadata">

**Author:** ![gilbertosj](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gilbertosj](https://forum.elixirforum.com/u/gilbertosj)\
**Post date:** [April 8, 2019, 10:59pm UTC](https://forum.elixirforum.com/t/error-controller-applying-where/21476/3 "2019-04-08T22:59:40Z")

</div>

that was it  
Thanks a lot for the help.
