2017-12-08 09:58:14 +01:00
|
|
|
defmodule Eventos.Events.Category do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
alias Eventos.Events.Category
|
|
|
|
|
|
|
|
|
|
|
|
schema "categories" do
|
2018-01-13 23:33:03 +01:00
|
|
|
field :description, :string
|
2017-12-08 09:58:14 +01:00
|
|
|
field :picture, :string
|
2018-01-13 23:33:03 +01:00
|
|
|
field :title, :string, null: false
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Category{} = category, attrs) do
|
|
|
|
category
|
2018-01-13 23:33:03 +01:00
|
|
|
|> cast(attrs, [:title, :description, :picture])
|
|
|
|
|> validate_required([:title])
|
2017-12-08 09:58:14 +01:00
|
|
|
|> unique_constraint(:title)
|
|
|
|
end
|
|
|
|
end
|