Comments (8)
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.
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.
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.
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
- 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
- If
1.9.1
works and1.9.2
doesn't then its isolated to the referenced PR and I have at least somewhere to start looking.
from money_sql.
I can confirm that flipping to Money.Ecto.Map.Type
solves my problems!
from money_sql.
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.
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.
Thanks for the kind words Greg, it's much appreciated and definitely keeps my. motivation high.
from money_sql.
Related Issues (20)
- `undefined function migrations_path/1` when attempting to compile HOT 3
- Ecto types return malformed error when casting invalid currency HOT 2
- Dependencie issue with ex_money 5.2 HOT 2
- Not compatible with Decimal 2.0 HOT 7
- Unmatched clause for `Cldr.Decimal.parse/1` HOT 1
- Composite type cast does not respect locales HOT 5
- Possible bug in ecto? Asking here first for clarification HOT 3
- Broken/Unsupported CompositeType defaults
- Checking if I receive notifications
- function Money.Ecto.Composite.Type.type/0 is undefined or private when using Ecto.Query.Api.type/2 HOT 7
- Getting `type/0` is undefined errors when upgrading HOT 6
- Add keyword list to error return from money_with_currency cast/1 HOT 3
- Add Ecto Changeset validations HOT 1
- Aggregate function treating null as zero amount HOT 1
- Is it able to change the behavior of to_string for `Money.Ecto.Composite.Type` ? HOT 7
- Cast function used to return error when currency is nil HOT 2
- Money.Ecto.Map.Type.embed_as/2 should return :dump instead of :self HOT 2
- Sum returns ERROR 42804 (datatype_mismatch) HOT 7
- Could not read file error after upgrading to 1.10.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from money_sql.