Protocol Ecto.Queryable not implemented for Item of type Atom

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

1 Like

(emphasis mine)

You likely have code like Repo.all(Item) so either use MyApp.Item or use an alias.

2 Likes

Thank you I think i see my issue based on your solution

1 Like

Thank you. it worked.

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?

The code you’ve shown correctly aliases Product, but that’s not what the error message is about!

My guess is that there’s a has_many :categories, Category in product.ex but no alias Hello.Catalog.Category.

1 Like

Thanks @al2o3cr , I had to put alias Hello.Catalog.Category in both product.ex and catalog.ex

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

Thanks @al2o3cr this helped me out too :+1: