AshMoney.Types.Money (ash_money v0.2.5)

View Source

A money type for Ash that uses the ex_money library.

When constructing a composite type, use a tuple in the following structure:

composite_type(%{currency: "USD", amount: Decimal.new("0")}}, AshMoney.Types.Money)

If you've added a custom type, like :money:

composite_type(%{currency: "USD", amount: Decimal.new("0")}, :money)

Constraints Options

  • :storage_type (atom/0) - The storage type for the money value. Can be :money_with_currency or :map. There is no difference between the two unless ex_money_sql is installed. The default value is :money_with_currency.

  • :ex_money_opts (keyword/0) - ex_money Money.new/3 Options - https://hexdocs.pm/ex_money/Money.html#new/3-options

  • :min - Enforces a minimum on the amount

  • :max - Enforces a maximum on the amount

Example

attribute :charge, :money do
  constraints: [
    min: Decimal.new("0"),
    max: Decimal.new("1000"),
    ex_money_opts: [
      no_fraction_if_integer: true,
      format: :short
    ]
  ]
end

Summary

Functions

handle_change?()

prepare_change?()