Git Product home page Git Product logo

Comments (8)

kipcole9 avatar kipcole9 commented on July 19, 2024 1

I've updated the readme to be as super clear and obvious as possible. And I've updated the changelog too.

Hopefully that means other people won't have the same issue I put you through.

from money_sql.

kipcole9 avatar kipcole9 commented on July 19, 2024

Apologies, that's extremely inconvenient.

The type {"USD", Decimal.new("50.00")} is the format that comes back from Postgrex for the money_with_currency composite type in Postgres. Is that correct in your case?

If so, the likely culprit is ex_money_sql and as a first measure I'd recommend first moving back to ex_money_sql 1.9.0.

There were some changes to the type definition in 1.9.2 that related to embedded schemas. By any chance would you be using embedded schemas with a money type in Postgres? That would be a second line of enquiry. Because money_sql itself doesn't use JSON encoding directly - it's only (as I understand it) when Ecto is encoding a map() type field or an embedded schema.

Hope that gives you a more specific place to look and one thing to try. If you are able to isolate the Ecto schema that is raising the issue and you are able to share it that would be extremely helpful.

from money_sql.

coladarci avatar coladarci commented on July 19, 2024

Thanks! Yes we definitely embed Money Objects - we can try rolling back, but what can I do to help sort out the potential bug around embedded moneys?

from money_sql.

kipcole9 avatar kipcole9 commented on July 19, 2024

My guess (and it's a guess) is that in your embedded schemas the type is Money.Ecto.Composite.Type when it needs to be Money.Ecto.Map.Type. It seems to have worked a bit by accident in earlier releases and I didn't have good enough test coverage.

I merged a PR that fixed some issues with embedded schemas but it may have introduced the issue you are seeing. If money_sql version 1.9.1 works but 1.9.2 doesn't then that helps narrow down where to look. I'm a little surprised though because the tuple form like {"USD", Decimal.new("50.00")} can only come from the composite type.

Summary

  1. An embedded money type needs to be Money.Ecto.Map.Type like this:
  schema "organizations" do
    embeds_many :customers, Customer do
      field :name, :string
      field :revenue, Money.Ecto.Map.Type, default: Money.new(:USD, 0)
    end
  end
  1. If 1.9.1 works and 1.9.2 doesn't then its isolated to the referenced PR and I have at least somewhere to start looking.

from money_sql.

coladarci avatar coladarci commented on July 19, 2024

I can confirm that flipping to Money.Ecto.Map.Type solves my problems!

from money_sql.

kipcole9 avatar kipcole9 commented on July 19, 2024

Phew, extremely happy to hear that. I will make a much clearer note in the readme and the changelog. The previous behaviour was erroneous and I'm surprised it actually worked - but clearly not a great upgrade experience.

from money_sql.

coladarci avatar coladarci commented on July 19, 2024

What made this wonderful is that I had zero doubt you'd have an answer within 24 hours (and more likely within a few) and you did not disappoint. I appreciate you and this library more than you can know!

from money_sql.

kipcole9 avatar kipcole9 commented on July 19, 2024

Thanks for the kind words Greg, it's much appreciated and definitely keeps my. motivation high.

from money_sql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.