Files
bDS2/lib/bds/media/translation.ex

54 lines
1.1 KiB
Elixir

defmodule BDS.Media.Translation do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :string, autogenerate: false}
@foreign_key_type :string
schema "media_translations" do
belongs_to :media, BDS.Media.Media,
foreign_key: :translation_for,
references: :id,
type: :string
field :project_id, :string
field :language, :string
field :title, :string
field :alt, :string
field :caption, :string
field :created_at, :integer
field :updated_at, :integer
end
def changeset(translation, attrs) do
translation
|> cast(
attrs,
[
:id,
:project_id,
:translation_for,
:language,
:title,
:alt,
:caption,
:created_at,
:updated_at
],
empty_values: [nil]
)
|> validate_required([
:id,
:project_id,
:translation_for,
:language,
:created_at,
:updated_at
])
|> foreign_key_constraint(:translation_for)
|> unique_constraint(:language, name: :media_translations_translation_language_idx)
end
end