Giter Club home page Giter Club logo

Comments (9)

davidkalosi avatar davidkalosi commented on August 24, 2024 2

I am using this. I ended up creating a MoneyBundle tailored to the needs of that specific project.

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <embeddable name="Money\Money">
    <field name="amount" type="integer"/>
    <field name="currency" type="currency" length="3"/>
  </embeddable>
</doctrine-mapping>

from money.

sagikazarmark avatar sagikazarmark commented on August 24, 2024

There were already a Doctrine Type which is removed now. The removed type can be found here. However it makes it a bit weird to store it in database, since the database value must be stored as string.

from money.

mathiasverraes avatar mathiasverraes commented on August 24, 2024

Storing it as a string makes perfect sense. I do that as default, unless I need to query the value -- and even in that case I might have both a money field with the string, and a split money_amount and money_currency field. Don't believe the normalisation hype :-)

In any case, I'm sure somebody has provided a doctrine embeddable for Money somewhere.

from money.

sagikazarmark avatar sagikazarmark commented on August 24, 2024

Well, I am sure you can understand why I say it is weird. Think about a distance measurement: you do not store it as a string with a unit. You specify a base and convert it if needed.

In case of currencies it is a bit hard, since the conversion rates are not simple(not just 10 for example) and are always changing. So from this point of view storing monetary values as string is ok.

In other cases (like an ecommerce site) the currency is not strongly tied to the actual value, since EVERY value has the same currency by default and usually this can be converted to another currency (with the CurrencyPair for example). So I would rather say storing integers is better when it is possible.

from money.

mathiasverraes avatar mathiasverraes commented on August 24, 2024

since EVERY value has the same currency by default

Never make assumptions about other domains :-)
I've worked in ecommerce where the prices of products were not converted.
Eg EUR 599 vs GBP 479. Shop owners don't want to list GBP 476.54 as the
price. Doing any kind of querying on prices there would have been
pointless. Full text searches were done in solr.

Not all value objects are measurements by the way. But I guess that is
rather off topic here.

On 27 August 2014 20:07, Márk Sági-Kazár [email protected] wrote:

Well, I am sure you can understand why I say it is weird. Think about a
distance measurement: you do not store it as a string with a unit. You
specify a base and convert it if needed.

In case of currencies it is a bit hard, since the conversion rates are not
simple(not just 10 for example) and are always changing. So from this point
of view storing monetary values as string is ok.

In other cases (like an ecommerce site) the currency is not strongly tied
to the actual value, since EVERY value has the same currency by default and
usually this can be converted to another currency (with the CurrencyPair
for example). So I would rather say storing integers is better when it is
possible.


Reply to this email directly or view it on GitHub
#50 (comment).

Mathias Verraes
[email protected]
http://verraes.net
@mathiasverraes http://twitter.com/mathiasverraes

from money.

sagikazarmark avatar sagikazarmark commented on August 24, 2024

I did not say correctly than, but usually (meaning open source Magento, OpenCart, Prestashop or the upcoming Sylius, etc) it is the case. Since I have no real experience with international ecommerce (there are not much international business like this in Hungary) I can't say for sure. However the point was to provide an understandable example where not storing the currency with the value is possible. And under these circumstances I still think storing integer values makes it easier to handle it as data. But I get it, in some cases it simply does not matter whether it is stored as integer or not. (Especially in PHP, where for example MySQL queries return all data as string)

from money.

sagikazarmark avatar sagikazarmark commented on August 24, 2024

This is an Entity, not a type. IMO it is wrong, because Money is a value object, which should rather be a type. Question: how do you handle the case when more than one entity requires a "money"? Do you even associate it to other entities?

from money.

davidkalosi avatar davidkalosi commented on August 24, 2024

@sagikazarmark - it is an embeddable thus a value object. not an entity. check the mapping file again.

from money.

sagikazarmark avatar sagikazarmark commented on August 24, 2024

Sorry, missed that.

from money.

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.