Created
January 8, 2016 13:52
-
-
Save terakilobyte/3a8f686698256d36c9f8 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
defmodule Votio.Topic do | |
use Votio.Web, :model | |
schema "topics" do | |
field :title, :string | |
field :categories, :map | |
field :voted_by, {:array, :id} | |
timestamps | |
end | |
@required_fields ~w(title categories) | |
@optional_fields ~w() | |
@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) | |
|> unique_constraint(:title) | |
|> validate_length(:categories, min: 2) | |
|> validate_length(:topic, min: 5) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment