Last active
February 15, 2017 04:47
-
-
Save josephan/8222f0e2bd3f9b5752f94aa55aca4b0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Programming Phoenix Version: P1.0 (April 2016) | |
# I have the following changeset for my User model: | |
def changeset(model, params \\ :empty) do | |
model | |
|> cast(params, ~w(name username), []) | |
|> validate_length(:username, min: 1, max: 20) | |
end | |
# but I get the following deprecation warning | |
# when I run the following line in `iex -S mix` | |
changeset = Rumbl.User.changeset(%Rumbl.User{username: "eric"}) | |
# warning: `Ecto.Changeset.cast/4` is deprecated, please use `cast/3` + `validate_required/3` instead | |
# (rumbl) web/models/user.ex:15: Rumbl.User.changeset/2 | |
# (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 | |
# (stdlib) erl_eval.erl:438: :erl_eval.expr/5 | |
# (elixir) src/elixir.erl:224: :elixir.erl_eval/3 | |
# | |
# So I changed the changeset to the following: | |
def changeset(model, params \\ :empty) do | |
model | |
|> cast(params, ~w(name username)) | |
|> validate_required([:name, :username]) | |
|> validate_length(:username, min: 1, max: 20) | |
end | |
# But then another deprecation warning is show: | |
# warning: passing :empty to Ecto.Changeset.cast/3 is deprecated, please pass an empty map or :invalid instead | |
# (rumbl) web/models/user.ex:15: Rumbl.User.changeset/2 | |
# (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 | |
# (stdlib) erl_eval.erl:438: :erl_eval.expr/5 | |
# (elixir) src/elixir.erl:224: :elixir.erl_eval/3 | |
# running the following works fine however: | |
changeset = Rumbl.User.changeset(%Rumbl.User{username: "eric"}, %{}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment