2018-01-13 23:33:03 +01:00
|
|
|
defmodule Eventos.Events.Participant do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Represents a participant, an account participating to an event
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
alias Eventos.Events.{Participant, Event}
|
|
|
|
alias Eventos.Accounts.Account
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
schema "participants" do
|
|
|
|
field :role, :integer
|
|
|
|
belongs_to :event, Event, primary_key: true
|
|
|
|
belongs_to :account, Account, primary_key: true
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Participant{} = participant, attrs) do
|
|
|
|
participant
|
|
|
|
|> cast(attrs, [:role, :event_id, :account_id])
|
|
|
|
|> validate_required([:role, :event_id, :account_id])
|
|
|
|
end
|
|
|
|
end
|