View Source Money.Validate (Money SQL v1.11.0)

Implements Ecto validations for the Money.t/0 type based upon the Money.Ecto.Composite.Type type.

Summary

Functions

Link to this function

validate_money(changeset, field, opts)

View Source
@spec validate_money(Ecto.Changeset.t(), atom(), Keyword.t()) :: Ecto.Changeset.t()

Validates the properties of a Money.t/0.

This function, including its options, is designed to mirror the function Ecto.Changeset.validate_number/3.

Options

  • :less_than
  • :greater_than
  • :less_than_or_equal_to
  • :greater_than_or_equal_to
  • :equal_to
  • :not_equal_to
  • :message - the message on failure, defaults to one of:
    • "must be less than %{money}"
    • "must be greater than %{money}"
    • "must be less than or equal to %{money}"
    • "must be greater than or equal to %{money}"
    • "must be equal to %{money}"
    • "must be not equal to %{money}"

Examples

validate_money(changeset, :value, less_than: Money.new(:USD, 200)) validate_money(changeset, :value, less_than_or_equal_to: Money.new(:USD, 200) validate_money(changeset, :value, less_than_or_equal_to: Money.new(:USD, 100)) validate_money(changeset, :value, greater_than: Money.new(:USD, 50)) validate_money(changeset, :value, greater_than_or_equal_to: Money.new(:USD, 50)) validate_money(changeset, :value, greater_than_or_equal_to: Money.new(:USD, 100))