I created the changeset function as specified in the book but I keep getting the following errors. So far the solutions I have seen online involve updating Ecto, which is not my issue as I am on the latest version. I also found the book to be pretty out of date (I bought it used). Which makes me happy that the codebase is evolving and getting better, but also making it difficult to learn.
On the def changeset line
:
Function changeset/1 has no local returnElixirLS Dialyzer
Function changeset/2 has no local returnElixirLS Dialyzer
And the following error on the cast(params....
line:
The call 'Elixir.Ecto.Changeset':cast
(_user@1 :: any(),
_params@1 :: any(),
[<<110,97,109,101>>, <<117,115,101,114,110,97,109,101>>],
[]) breaks the contract
('Elixir.Ecto.Schema':t() | t() | {data(), types()},
#{binary() := term()} | #{atom() := term()} | 'invalid',
[atom()],
'Elixir.Keyword':t()) ->
t()ElixirLS Dialyzer
Here is the full code:
defmodule Rumbl.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :name, :string
field :username, :string
field :password, :string, virtual: true
field :password_hash, :string
timestamps()
end
def changeset(user, params \\ :empty) do
user
|> cast(params, ~w(name username), [])
|> validate_length(:username, min: 1, max: 20)
end
end