feat: base work for post translations
This commit is contained in:
48
lib/bds/posts/translation.ex
Normal file
48
lib/bds/posts/translation.ex
Normal file
@@ -0,0 +1,48 @@
|
||||
defmodule BDS.Posts.Translation do
|
||||
@moduledoc false
|
||||
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :string, autogenerate: false}
|
||||
@foreign_key_type :string
|
||||
@statuses [:draft, :published]
|
||||
|
||||
schema "post_translations" do
|
||||
belongs_to :post, BDS.Posts.Post, foreign_key: :translation_for, references: :id, type: :string
|
||||
|
||||
field :project_id, :string
|
||||
field :language, :string
|
||||
field :title, :string
|
||||
field :excerpt, :string
|
||||
field :content, :string
|
||||
field :status, Ecto.Enum, values: @statuses, default: :draft
|
||||
field :created_at, :integer
|
||||
field :updated_at, :integer
|
||||
field :published_at, :integer
|
||||
field :file_path, :string, default: ""
|
||||
field :checksum, :string
|
||||
end
|
||||
|
||||
def changeset(translation, attrs) do
|
||||
translation
|
||||
|> cast(attrs, [
|
||||
:id,
|
||||
:project_id,
|
||||
:translation_for,
|
||||
:language,
|
||||
:title,
|
||||
:excerpt,
|
||||
:content,
|
||||
:status,
|
||||
:created_at,
|
||||
:updated_at,
|
||||
:published_at,
|
||||
:file_path,
|
||||
:checksum
|
||||
], empty_values: [nil])
|
||||
|> validate_required([:id, :project_id, :translation_for, :language, :title, :status, :created_at, :updated_at])
|
||||
|> foreign_key_constraint(:translation_for)
|
||||
|> unique_constraint(:language, name: :post_translations_translation_language_idx)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user