# `Money.Ecto.Composite.Type`
[🔗](https://github.com/kipcole9/money_sql/blob/v2.0.0/lib/money/ecto/money_ecto_composite_type.ex#L2)

Implements 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,

# `cast`

Casts user input into `t:Money.t/0` struct.

See `Money,Ecto.Composite.Type.cast/2`.

# `cast`

Casts user input into `t: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 `Localize.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

* `money` is a map containing the keys `currency` and`amount`
  as either strings or atoms OR a string that can be parsed
  to produce a `t:Money.t/0` struct.

* `params` is a keyword list of option that is passed to
  `Money.new/3`.

### Returns

* `{:ok, money}` or

* `:error`

### Notes

* If either the `money` or `amount` values are
  `nil`, then `{:ok, nil}` will be returned.

* `amount` can be a string, an integer or a
  `t:Decimal.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.

# `equal?`

Compares two money structs and return an boolean
indicating if they are equal or not.

### Arguments

* `money1` is any `t:Money.t/0`

* `money2` is any `t:Money.t/0`

### Returns

* `true` or `false`.

# `equal?`

Compares two money structs and return an boolean
indicating if they are equal or not.

### Arguments

* `money1` is any `t:Money.t/0`

* `money2` is any `t:Money.t/0`

* `params` which is ignored.

### Returns

* `true` or `false`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
