View Source EctoI18n.Changeset (ecto_i18n v0.4.1)

Provides i18n extensions for Ecto.Changeset.

Summary

Functions

Casts field which is added by field_i18n/_ macro.

Functions

Link to this function

cast_i18n(changeset, name, opts \\ [])

View Source

Casts field which is added by field_i18n/_ macro.

It is built on the top of Ecto.Changeset.cast_embed/3.

Example

defmodule MyApp.Shop.Product do
  use Ecto.Schema
  import Ecto.Changeset
  use EctoI18n.Schema, locales: ["en", "zh-Hans"]
  import EctoI18n.Changeset

  schema "products" do
    field :sku, :string
    field_i18n :name, :string
  end

  def changeset(product, attrs) do
    product
    |> cast(attrs, [:sku])
    |> cast_i18n(:name, required: true)
  end
end

In above code, changeset/2 equals to:

def changeset(product, attrs) do
  product
  |> cast(attrs, [:sku])
  |> cast_embed(:name_i18n, required: true)
end