With this minimal struct:
defmodule Auction.Item do
defstruct [:id, :title, :description, :ends_at]
def changeset(item, params \\ %{}) do
item
|> Ecto.Changeset.cast(params, [:title, :description, :ends_at])
end
end
the intent is to slowly, gradually introduce/use Ecto.Changeset
.
At the first exploratory steps, the following issue is encountered:
iex> item = Auction.list_items() |> hd()
%Auction.Item{ # snip…
iex> Auction.Item.changeset(item)
** (UndefinedFunctionError) function Auction.Item.__changeset__/0 is undefined or private. Did you mean one of:
* changeset/1
* changeset/2
(auction) Auction.Item.__changeset__()
(ecto) lib/ecto/changeset.ex:429: Ecto.Changeset.cast/4
Ecto 2.2.9 is being used, and looking at
- the error message,
- the docs and
- the code for
Ecto.Changeset.cast/4
,
I am stuck on understanding what is happening and how to move forward.
The one finding that seems relevant is this comment/answer on SO suggesting that cast
might not work without the struct having a schema defined.
I’m trying to better understand how this works and what options are there. My current understanding is that for the Auction.Item
defined above, we need to either:
- define a schema for the struct
- pass in the
data
argument in the{data, types}
format - any other option?
Thanks for your help!