Money v1.6.0 Money.Ecto.Type View Source

WARNING: this module is deprecated. Use Money.Ecto.Amount.Type module instead. Provides a type for Ecto usage. The underlying data type should be an integer.

This type expects you to use a single currency. The currency must be defined in your configuration.

config :money, default_currency: :GBP

Migration Example

create table(:my_table) do add :amount, :integer end

Schema Example

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

Link to this section Summary

Functions

cast(val) deprecated

Casts the given input to the custom type.

dump(int) deprecated

Dumps the given term into an Ecto native type.

load(int) deprecated

Loads the given term into a custom type.

type() deprecated

Returns the underlying schema type for the custom type.

Link to this section Functions

This function is deprecated. Use Money.Ecto.Amount.Type.cast/1 instead.

Casts the given input to the custom type.

This callback is called on external input and can return any type, as long as the dump/1 function is able to convert the returned value into an Ecto native type. There are two situations where this callback is called:

  1. When casting values by Ecto.Changeset
  2. When passing arguments to Ecto.Query

When returning {:error, keyword()}, the returned keyword list will be preserved in the changeset errors, similar to Changeset.add_error/4. Passing a :message key, will override the default message. It is not possible to override the :type key.

For {:array, CustomType} or {:map, CustomType} the returned keyword list will be erased and the default error will be shown.

Callback implementation for Ecto.Type.cast/1.

Link to this function

dump(int)

View Source
dump(integer() | Money.t()) :: {:ok, :integer}
This function is deprecated. Use Money.Ecto.Amount.Type.dump/1 instead.

Dumps the given term into an Ecto native type.

This callback is called with any term that was stored in the struct and it needs to validate them and convert it to an Ecto native type.

Callback implementation for Ecto.Type.dump/1.

This function is deprecated. Use Money.Ecto.Amount.Type.load/1 instead.

Loads the given term into a custom type.

This callback is called when loading data from the database and receives an Ecto native type. It can return any type, as long as the dump/1 function is able to convert the returned value back into an Ecto native type.

Callback implementation for Ecto.Type.load/1.

Link to this function

type()

View Source
type() :: :integer
This function is deprecated. Use Money.Ecto.Amount.Type.type/0 instead.

Returns the underlying schema type for the custom type.

For example, if you want to provide your own date structures, the type function should return :date.

Note this function is not required to return Ecto primitive types, the type is only required to be known by the adapter.

Callback implementation for Ecto.Type.type/0.