kipcole9 / money_sql

Money functions for the serialization of a money data type in Elixir
Other
28 stars 18 forks source link

Broken/Unsupported CompositeType defaults #13

Closed emaiax closed 3 years ago

emaiax commented 3 years ago

Having field defaults in a schema seems to be broken or unsupported.

  schema "my table" do
    field :value, Money.Ecto.Composite.Type, default: Money.new(:BRL, 0)
  end

Example:

     Assertion with == failed
     code:  assert bc_november.value == Money.new(:BRL, 0)
     left:  %Money{amount: #Decimal<0>, currency: :BRL, format_options: [{:default, #Money<:BRL, 0>}]}
     right: %Money{amount: #Decimal<0>, currency: :BRL, format_options: []}

Shouldn't we support https://hexdocs.pm/ecto/Ecto.Schema.html#field/3 options as well? default at least. Mostly because even if the value isn't given, it defaults to something.

I'd more than happy to fix this. 👍