View Source TranslaTable.Schema (TranslaTable v0.3.1)
TranslaTable.Schema
will help casting translation module into your schema.
Examples
You can define your schema module with the TranslaTable.Schema
macro to cast and define the has many association:
defmodule MyApp.Post do
use Ecto.Schema
use TranslaTable.Schema,
translation_schema: MyApp.PostTranslation
import Ecto.Changeset
schema "post" do
field :title, :string
field :description, :string
field :author, :string
field :slug, :string
has_many_translations()
timestamps()
end
@doc false
def changeset(post, attrs) do
post
|> cast(attrs, [:title, :description, :author, :slug])
|> cast_translation()
end
end