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

Provides a type for Ecto to store a multi-currency price. The underlying data type should be a map(JSON). Suitable for databases that do not support composite types, but support JSON (e.g. MySQL).

migration

Migration

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

schema

Schema

schema "my_table" do
  field :price, Money.Ecto.Map.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

Callback implementation for Ecto.Type.cast/1.

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

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

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

@spec load(map()) :: {:ok, Money.t()}

Callback implementation for Ecto.Type.load/1.

@spec type() :: :map

Callback implementation for Ecto.Type.type/0.