Hello,
I have the following error when I try to execute change_question
:
protocol Ecto.Queryable not implemented for %MyApp.Quiz.Question{meta: ecto.Schema.Metadata…
def change_question(%Question{} = question) do
question
|> with_collection_assoc()
|> Question.changeset(%{})
end
def with_collection_assoc(query) do
from q in query, preload: [:collection] # <- fails here
end
defmodule MyApp.Quiz.Question do
use MyApp.Schema
import Ecto.Changeset
schema "questions" do
field :title, :map
field :type, :string
field :text, :map
belongs_to :collection, MyApp.Quiz.Collection
end
def changeset(question, attrs) do
question
|> cast(attrs, [:title, :type, :text])
|> cast_assoc(:collection)
|> validate_required([:collection, :title, :type, :text])
end
Anyone can explain what the error is about?
Isn’t a Schema struct Queryable?