mobilizon.chapril.org-mobil.../lib/mobilizon/events/track.ex

43 lines
934 B
Elixir
Raw Normal View History

defmodule Mobilizon.Events.Track do
@moduledoc """
2019-09-13 01:01:17 +02:00
Represents a track for an event (such as a theme) having multiple sessions.
"""
2019-09-13 01:01:17 +02:00
use Ecto.Schema
2019-09-13 01:01:17 +02:00
import Ecto.Changeset
2019-09-13 01:01:17 +02:00
2019-09-13 01:55:45 +02:00
alias Mobilizon.Events.{Event, Session}
2019-09-13 01:01:17 +02:00
@type t :: %__MODULE__{
color: String.t(),
description: String.t(),
name: String.t(),
event: Event.t(),
sessions: [Session.t()]
}
@required_attrs [:name, :description, :color]
@optional_attrs [:event_id]
@attrs @required_attrs ++ @optional_attrs
schema "tracks" do
field(:color, :string)
field(:description, :string)
field(:name, :string)
2019-09-13 01:01:17 +02:00
belongs_to(:event, Event)
has_many(:sessions, Session)
timestamps()
end
@doc false
2019-09-13 01:01:17 +02:00
@spec changeset(t, map) :: Ecto.Changeset.t()
2019-09-13 01:55:45 +02:00
def changeset(%__MODULE__{} = track, attrs) do
track
2019-09-13 01:01:17 +02:00
|> cast(attrs, @attrs)
|> validate_required(@required_attrs)
end
end