684 B · text 5af55d9
defmodule GitGud.Labels.Labeling do
use Ecto.Schema
import Ecto.Changeset
alias GitGud.Labels.Label
@valid_target_types ~w(issue pull_request)
schema "labelings" do
belongs_to :label, Label
field :target_type, :string
field :target_id, :integer
timestamps(type: :utc_datetime, updated_at: false)
end
def changeset(labeling, attrs) do
labeling
|> cast(attrs, [:label_id, :target_type, :target_id])
|> validate_required([:label_id, :target_type, :target_id])
|> validate_inclusion(:target_type, @valid_target_types)
|> unique_constraint([:label_id, :target_type, :target_id])
end
def target_types, do: @valid_target_types
end