-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueObject Money custom type #10335
Comments
Sorry, but I have no idea what you're asking for. |
I have updated the description of IDIA.
Do you see any negative effect of introducing the extension to ORM API? |
The change would need to be done in dbal and the ORM module... |
Hi, @Ocramius. I have found the following quote of yours:
Could you share the link to this one so I could get to know more detail about it? Why does Dependency Injection assum complexity? |
All right, I'm closing this issue because all APIs that you want to change are DBAL ones. You're in the ORM repository here. You might want to contribute to the discussion in doctrine/dbal#2841. |
I don't have a link, but the type system of DBAL v2 (not sure about v3) uses the flyweight pattern, and is not suited for DI in its form. |
Look at the DBAL repo, I've taken steps toward this. Might be on the latest branch, and the work is not finished IIRC |
The problem
The money library stores the amount as a string for example 1.89 USD is stored inside class Money as {amount: "189", currency: "USD"}
Storing the amount in the database as a string would prevent sorting them by value, the decimal type is more appropriate for this task.
The problem is that I need to convert
amount: "189"
to the database type as1.89
and back.To be able to convert I need to know how many digits are after the decimal point for example bitcoin has 8 digits. This information could be retrieved from this method
1.89
BTC would need to be converted to189000000
(Satoshi)1.89
ETH would need to be converted to189000000000000000000
(Wei)The bakc conversion should be possible as well:
189000000
BTC(Satoshi) =>1.89
BTC189000000000000000000
ETH(Wei) =>1.89
ETHI see the problem above could be solved as follows:
From the doctrine side the following change will be needed:
Example of how it will be used.
https://github.com/Legion112/doctrine-embadable-share-column/blob/main/src/MoneyType.php and https://github.com/Legion112/doctrine-embadable-share-column/blob/main/src/Money.php
Why it is better to allow those manipulations on the ORM side?
In case of not allowed to do the conversion on the ORM side, we are limited to storing the amount in a database as a string. Which potentially removes the following features:
The text was updated successfully, but these errors were encountered: