translecto v0.0.2 Translecto.Schema.Translatable

Reference a translatable field in the schema.

This module coincides with the migration function Translecto.Migration.translate/2. To correctly use this module a schema should call use Translecto.Schema.Translatable.

Summary

Macros

Expose a field as being translatable to the schema

Macros

translatable(name, queryable, opts \\ [])

Specs

translatable(term, atom, module, keyword) :: Macro.t

Expose a field as being translatable to the schema.

The name of the field specified should coincide with a migration table field that was made using Translecto.Migration.translate/2.

The queryable should be the translation module (schema) that represents the translation table.

defmodule Ingredient do
    use Translecto.Schema.Translatable

    schema "ingredients" do
        translatable :name, Ingredient.Translation
    end

    def changeset(struct, params \\ %{}) do
        struct
        |> translatable_changeset(params, [:name])
        |> validate_required([:name])
    end
end