cannery/lib/cannery/containers/container_tag.ex

38 lines
1000 B
Elixir
Raw Normal View History

2021-09-12 19:27:18 -04:00
defmodule Cannery.Containers.ContainerTag do
2022-01-22 21:40:29 -05:00
@moduledoc """
Thru-table struct for associating Cannery.Containers.Container and
Cannery.Tags.Tag.
"""
2021-09-12 19:27:18 -04:00
use Ecto.Schema
import Ecto.Changeset
2022-01-22 21:40:29 -05:00
alias Cannery.{Containers.Container, Containers.ContainerTag, Tags.Tag}
2021-09-12 19:27:18 -04:00
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "container_tags" do
2022-01-22 21:40:29 -05:00
belongs_to :container, Container
belongs_to :tag, Tag
2021-09-12 19:27:18 -04:00
timestamps()
end
2022-01-22 21:40:29 -05:00
@type t :: %ContainerTag{
2021-09-12 19:27:18 -04:00
id: Ecto.UUID.t(),
2022-01-22 21:40:29 -05:00
container: Container.t(),
2021-09-12 19:27:18 -04:00
container_id: Ecto.UUID.t(),
2022-01-22 21:40:29 -05:00
tag: Tag.t(),
2021-09-12 19:27:18 -04:00
tag_id: Ecto.UUID.t(),
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
@doc false
2022-01-22 21:40:29 -05:00
@spec changeset(ContainerTag.t(), map()) :: Ecto.Changeset.t()
2021-09-12 19:27:18 -04:00
def changeset(container_tag, attrs) do
container_tag
|> cast(attrs, [:tag_id, :container_id])
|> validate_required([:tag_id, :container_id])
end
end