defmodule Outlook.Translations.Translation do use Ecto.Schema import Ecto.Changeset alias Outlook.Accounts.User alias Outlook.Articles.Article alias Outlook.Translations.TranslationUnitsMap schema "translations" do field :content, TranslationUnitsMap field :date, :utc_datetime field :lang, :string, default: "DE" field :public, :boolean, default: false field :teaser, :string field :title, :string field :unauthorized, :boolean, default: false belongs_to :user, User belongs_to :article, Article timestamps() end @doc false def changeset(translation, attrs) do translation |> cast(attrs, [:lang, :title, :teaser, :date, :public, :unauthorized, :article_id]) |> cast(attrs, [:content]) |> validate_required([:lang, :title, :content, :date, :public, :unauthorized, :article_id]) |> unique_constraint([:lang, :article_id], message: "translation for this language already exists", name: :article_id_lang_unique_index) end end