Last active
November 30, 2018 21:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this gotcha