Created
May 23, 2019 15:12
-
-
Save BrandonMathis/0c58da56e7f0354100f1db5f4dbb1dc6 to your computer and use it in GitHub Desktop.
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
defmodule MyApp.User do | |
use MyApp.Web, :model | |
use Arc.Ecto.Model | |
schema "users" do | |
field :avatar, MyApp.Avatar.Type | |
field :username, :string | |
field :email, :string | |
timestamps | |
end | |
@required_fields ~w() | |
@optional_fields ~w(username email) | |
@required_file_fields ~w() | |
@optional_file_fields ~w(avatar) | |
@doc """ | |
Creates a changeset based on the `model` and `params`. | |
If no params are provided, an invalid changeset is returned | |
with no validation performed. | |
""" | |
def changeset(model, params \\ :empty) do | |
model | |
|> cast(params, @required_fields, @optional_fields) | |
|> cast_attachments(params, @required_file_fields, @optional_file_fields) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment