gjaldon / ecto_enum

Ecto extension to support enums in models
MIT License
562 stars 131 forks source link

Queries don't seem to work #10

Closed clessg closed 8 years ago

clessg commented 8 years ago

Given:

from(f in Friendship, where: f.type == :friend) |> Repo.all()

I receive the following error:

iex(2)> from(f in Friendship, where: f.type == :friend) |> Repo.all()
** (Ecto.Query.CompileError) `:friend` is not a valid query expression
      (ecto) expanding macro: Ecto.Query.where/3
             iex:2: (file)
      (ecto) expanding macro: Ecto.Query.from/2
             iex:2: (file)
    (elixir) expanding macro: Kernel.|>/2
             iex:2: (file)

friendship.ex:

defmodule Eclipse.Friendship do
  use Eclipse.Web, :model

  import EctoEnum
  defenum FriendshipTypeEnum, friend: 0, blocked: 1

  schema "friendships" do
    field :type, FriendshipTypeEnum
    ...
  end
  ...
end
jerodsanto commented 8 years ago

With Ecto 2 you need to pin the :friend atom. Try this:

from(f in Friendship, where: f.type == ^:friend) |> Repo.all()
clessg commented 8 years ago

Thank you! I'll make a PR to fix the docs.