defmodule Ammoprices.Catalog.Caliber do @moduledoc false use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "calibers" do field :name, :string field :slug, :string field :category, :string field :aliases, {:array, :string}, default: [] has_many :products, Ammoprices.Catalog.Product timestamps(type: :utc_datetime) end def changeset(caliber, attrs) do caliber |> cast(attrs, [:name, :slug, :category, :aliases]) |> validate_required([:name, :slug, :category]) |> validate_inclusion(:category, ~w(handgun rifle rimfire shotgun)) |> unique_constraint(:slug) end end