Money.Ecto.Composite.Type (Money SQL v1.11.1)
View SourceImplements the Ecto.Type behaviour for a user-defined Postgres composite type
called :money_with_currency.
This is the preferred option for Postgres database since the serialized money amount is stored as a decimal number,
Summary
Functions
Casts user input into Money.t/0 struct.
See Money,Ecto.Composite.Type.cast/2.
Casts user input into Money.t/0 struct.
Its important to note that user input is expected
to be in the format expected for the current locale
(as determined by Cldr.get_locale/0) or in the locale
specified by the :locale parameter.
This can lead to unexpected results if the locale and the user data are not aligned. Consider the following example.
The current locale is
:de. This means that the decimal separatator is defined ot be,and the grouping separatr is defined to be.The user data (often, but not always, from a form) is
%{"currency" => "EUR", amount: "1.00"}.
In this case cast/2 will return the equivalent of
Money.new(:EUR, "100") not Money.new(:EUR, "1.00").
Arguments
moneyis a map containing the keyscurrencyandamountas either strings or atoms OR a string that can be parsed to produce aMoney.t/0struct.paramsis a keyword list of option that is passed toMoney.new/3.
Returns
{:ok, money}or:error
Notes
If either the
moneyoramountvalues arenil, then{:ok, nil}will be returned.amountcan be a string, an integer or aDecimal.t/0.If a string is parsed then an attempt to parse the string into a currency and an amount is made using
Money.parse/2. Parsing is locale specific.
Compares two money structs and return an boolean indicating if they are equal or not.
Arguments
Returns
trueorfalse.
Compares two money structs and return an boolean indicating if they are equal or not.
Arguments
Returns
trueorfalse.