Closed shahryarjb closed 3 years ago
It seems this is caused by the only
option specifying :name
and :short_description
fields, but the struct itself not having a :name
field i could see in the schema description.
We should probably do some sort of validation of the options, to produce such errors at compile-time.
@michalmuskala
def encode(%{id: id, title: title, short_description: short_description, description: description, image: image, alias_link: alias_link, consulting_category_id: consulting_category_id}, {escape, encode_map})
this is the last line of my error, all the field I selected exist in my schema:
defmodule Joboffer.Admin.Consulting.ConsultingCategorySchema do
use Ecto.Schema
@derive {Jason.Encoder, only: [:id, :title, :short_description, :description, :image, :alias_link, :consulting_category_id]}
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "consulting_categories" do
field :title, :string, size: 150, null: false
field :short_description, :string, size: 164, null: true
field :description, :string, null: true
field :image, :string, size: 200, null: true
field :alias_link, :string, size: 200, null: false
field :status, :boolean, null: false
has_many :consulting_headlines, Joboffer.Admin.Consulting.ConsultingHeadlineSchema, foreign_key: :consulting_category_id, on_delete: :nothing
has_many :consulting_answers, Joboffer.Admin.Consulting.ConsultingAnswerSchema, foreign_key: :consulting_category_id, on_delete: :nothing
timestamps()
end
@all_fields ~w(title short_description description image alias_link status)a
@all_required ~w(title alias_link status)a
end
In this new error, to me, it looks like the consulting_category_id
field does not exist
Thanks, it is fixed, would it show us better error?
Hi, I have a nested preload which I need to convert to a json in my controller and I used @drive in my schema file, but when I call it, it shows me this error:
elixir: v1.11.1 phoenix: 1.5.6 mac the last version
my schema file:
full terminal error:
my controller:
my query