Working my way through the Phoenix in Action book at chapter 7.5.3, and I’m getting the following error:
iex(1)> Auction.list_items()
** (Protocol.UndefinedError) protocol Ecto.Queryable not implemented for Item of type Atom, the given module does not exist. This protocol is implemented for the following type(s): Atom, BitString, Ecto.Query, Ecto.SubQuery, Tuple
(ecto) lib/ecto/queryable.ex:40: Ecto.Queryable.Atom.to_query/1
(ecto) lib/ecto/repo/queryable.ex:14: Ecto.Repo.Queryable.all/3
I’m sort of stuck as I had this working yesterday. Help Please. This is my repo mpchean/auction_umbrella
Facing the same problem while going through the Phoenix Context Guide.
The error message is:
protocol Ecto.Queryable not implemented for Category of type Atom, the given module does not exist. This protocol is implemented for the following type(s): Atom, BitString, Ecto.Query, Ecto.SubQuery, Tuple
In my Catalog.ex file (Catalog is the context for Category and Product), I have the function defined as:
defmodule Hello.Catalog do
@moduledoc """
The Catalog context.
"""
import Ecto.Query, warn: false
alias Hello.Repo
alias Hello.Catalog.Product
...
def get_product!(id) do
Product |> Repo.get(id) |> Repo.preload(:categories)
end
...
The get_product! function is where the error originates from when I visit /products/1
I guess the alias is already given, so why is it still causing the error?
Bumped into the same issue while reading this old book. Basically, the Item has to continue to be imported, otherwise it is considered as something else:
# alias Auction.{FakeRepo, Item}
alias Auction.{Item}
# @repo FakeRepo
@repo Auction.Repo