Jira issue originally created by user acasademont:
Decimal type in mysql converts as a string in php. This is great as Decimal has a much higher precision than a float or double and that precision would be lost if converted to a float in PHP. Fine! But when doing calculations (as my numbers do not require an enormous precision gmp_ functions are not necessary) php converts these strings into floats. Then, when computing the changeset, as the value is compared with === is marked as a change even though there is none ("5.00" string vs 5.00 float) and an UPDATE for that row is made. Would it be possible to check only for simple equality "==" instead of type equality "===" when dealing with scalar types?
Another example of this would be the boolean type, that it is stored as an integer 1 in mysql but converted to a boolean true in php. If during the execution of my code that boolean gets converted to an integer 1, that will trigger an UPDATE also because 1 !== true.
Should this be my responsability or doctrine should be a little more flexible regarding comparisons? Thanks!!
Comment created by @ocramius:
Hi there!
Actually, doctrine orm converts floats from DB string to double at https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/FloatType.php#L52 . Keeping the correct type in for your fields is up to you, so be sure to cast in every setter :)
Comment created by acasademont:
Hi marco!
Actually i am using DECIMAL (or NUMERIC), not FLOAT, That type is not casted as it would lose precision. Therefore, my problem is when working with DECIMAL (Which is, btw, the type that mysql recommends for storing money values)
thet
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/DecimalType.php
Comment created by @ocramius:
Unsure if the cast should happen in the type (just ignorant about the implication in precision), but I'll suggest it then.
Comment created by acasademont:
It should not happen as the DECIMAL type in MySQL has much more precision than a double or float in PHP. It was previously cast but there was an issue regarding this cast and the cast was deleted
http://www.doctrine-project.org/jira/browse/DBAL-121
After that, in another issue a user points out the same problem i am facing, that i have to cast back to string if i do not want doctrine to issue an UPDATE command for values that have not changed
http://www.doctrine-project.org/jira/browse/DBAL-180
As i said, my only point is that maybe, when computing the changeset, the comparison for scalar types should be more relaxed with a == instead of a ===
Comment created by @ocramius:
Don't think this can be done, as you don't really know what types (and so also the conversion rules) the user applies to his own model. I wouldn't do that, leaving the implementor of the entities to have strict checks on types during operations in setters...