kipcole9 / money_sql

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

fix(equal/3, embed_as): equal/3 should rely on Money.equal/2 #19

Closed seantanly closed 2 years ago

seantanly commented 2 years ago

The default implementation from Ecto for Ecto.ParameterizedType.equal/3 is doing

def equal?(term1, term2, _params), do: term1 == term2

which results in changeset wrongly reporting changes although params passed are equal to model's value when compared using Money.equal/2.

Instead, Money.equal/2 should be used for money comparison.

Ref: https://github.com/elixir-ecto/ecto/blob/dc568c3b619a71511b275e609c89e530c011da04/lib/ecto/parameterized_type.ex#L190

Also added function head and base implementation for embed_as that is defdelegated from Money.Ecto.Map.Type to Money.Ecto.Composite.Type.

seantanly commented 2 years ago

Looks like the to_equal/3 function is recently fixed. 👍

This PR in addition adds unit test for that and fixes the defdelegate for embed_as/2. Also applied mix format based on elixir 1.13.

kipcole9 commented 2 years ago

I have published ex_money_sql version 1.5.2 with the following changeling entry:

Bug Fixes

Thanks for the report and the PR, much appreciated!