Last active
July 24, 2017 20:44
-
-
Save PragTob/797c4e49489450e2d5d391607f0c70b6 to your computer and use it in GitHub Desktop.
small ecto changeset example
This file contains 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
def new_changeset(model, params \\ %{}) do | |
model | |
|> cast(params, ~w(name username)) | |
|> validate_required(~w(name username)) | |
|> unique_constraint(:username) | |
|> validate_length(:username, min: 1, max: 20) | |
end | |
def registration_changeset(model, params) do | |
model | |
|> new_changeset(params) | |
|> cast(params, ~w(password)) | |
|> validate_required(~w(password)) | |
|> validate_length(:password, min: 6, max: 100) | |
|> put_pass_hash() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment