View Source Money.Ecto.Composite.Type (Money v1.12.4)

Provides a type for Ecto to store a multi-currency price. The underlying data type should be an user-defined Postgres composite type :money_with_currency.

migration

Migration

execute "CREATE TYPE public.money_with_currency AS (amount integer, currency varchar(3))"

create table(:my_table) do
  add :price, :money_with_currency
end

schema

Schema

schema "my_table" do
  field :price, Money.Ecto.Composite.Type
end

Link to this section Summary

Functions

Callback implementation for Ecto.Type.cast/1.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.

Link to this section Functions

@spec cast(Money.t() | {integer(), String.t()} | map() | any()) ::
  :error | {:ok, Money.t()}

Callback implementation for Ecto.Type.cast/1.

@spec dump(any()) :: :error | {:ok, {integer(), String.t()}}

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

@spec load({integer(), atom() | String.t()}) :: {:ok, Money.t()}

Callback implementation for Ecto.Type.load/1.

@spec type() :: :money_with_currency

Callback implementation for Ecto.Type.type/0.