Skip to content

Instantly share code, notes, and snippets.

@diogovk
Last active November 30, 2018 21:31
Show Gist options
  • Save diogovk/295e07380af4dc36b520 to your computer and use it in GitHub Desktop.
Save diogovk/295e07380af4dc36b520 to your computer and use it in GitHub Desktop.
protocol Ecto.Queryable not implemented for <Module>, the given module does not exist
defmodule Freshcards.Post do
use Freshcards.Web, :model
schema "posts" do
field :title, :string
belongs_to :user, Freshcards.User # right!
# belongs_to :user, User <-- wrong
timestamps
end
@required_fields ~w(title, user_id)
@optional_fields ~w()
def changeset(model, params \\ nil) do
cast(model, params, @required_fields, @optional_fields)
end
end
alias Freshcards.Post
alias Freshcards.User # <-Doing the alias here will not allow the schema "posts" to "see" the module User.
# The alias should be done inside the module!
# And that's why when we user preload() on a post we get:
# "protocol Ecto.Queryable not implemented for <Module>, the given module does not exist"
@denvaar
Copy link

denvaar commented Oct 22, 2017

Thank you for this gotcha

@denvaar
Copy link

denvaar commented Oct 5, 2018

Thank you again from this gotcha 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment