-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
...warning: Ecto.Changeset.cast/4
is deprecated, please use cast/3
+ validate_required/3
instead
#35
Comments
@nelsonic I may be totally off the mark, but what happens if you change:
to
I tried something similar to that and it seemed to work (I'm not as far through the book as you so I can't run the example you are running just yet). |
For anyone following "Programming Pheonix" around page 60: @des-des and I were running into the same warnings and ended up doing the below def changeset(model, params \\ :invalid) do
model
|> cast(params, ~w(name username))
|> validate_required([:name, :username])
|> validate_length(:username, min: 1, max: 20)
end
|
I would add to that: the book adds a uniqueness index to the def changeset(model, params \\ :invalid) do
model
|> cast(params, ~w(name username))
|> validate_required([:name, :username])
|> unique_constraint(:username)
|> validate_length(:username, min: 1, max: 20)
end I would recommend also adding the |
@untra thanks for sharing. I have a slight variation on this: def changeset(model, params \\ :invalid) do
model
|> cast(params, ~w(name username))
|> validate_required([:name, :username])
|> validate_length(:username, min: 1, max: 20)
|> unique_constraint(:username) # save the unique_constraint for last as it "hits" the DB. ;-)
end |
running
mix test
on page 134but get the following warning message:
Looked at: https://hexdocs.pm/ecto/Ecto.Changeset.html
tried changing the code in
web/models/video.ex:20-25
from:To:
or:
but tests failed:
figured I need to call
cast
on all the fields as a single list.read http://learningwithjb.com/posts/concat-lists-with-elixir
So changed to:
and ran:
mix test
and got:I would like to
continue
spending time on this but I suspect that it will become clear to me later in the book or through more practice/understanding so I'm just going to leave this issue open incase
someoneelse
knows how to "fix" it ...The text was updated successfully, but these errors were encountered: