Skip to content

Instantly share code, notes, and snippets.

@BrandonMathis
Created May 23, 2019 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrandonMathis/0c58da56e7f0354100f1db5f4dbb1dc6 to your computer and use it in GitHub Desktop.
Save BrandonMathis/0c58da56e7f0354100f1db5f4dbb1dc6 to your computer and use it in GitHub Desktop.
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