Unnecessary decimal updates #5086

Closed
opened 2026-01-22 14:57:59 +01:00 by admin · 1 comment
Owner

Originally created by @Bordovsky on GitHub (Apr 8, 2016).

Originally assigned to: @Ocramius on GitHub.

Hi. I would like to make pull request, but when I tried add my branch/code I got 403 response. I will add code here, since it is nothing huge. I hope you don't mind.

When working around decimals in php, they change type. Since doctrine see them as strings and we works with them as numbers. It leads into unnecessary change set values in persisting which doesn't do any real change.

Workaround in entities seems difficult so I added few lines of code into UnitOfWork and it works, and pass all tests. I suppose others wouldn't mind if change set contained only real changes.

Here is code, it belongs on line 665 in UnitOfWork.php:

            if (array_key_exists($propName,$class->fieldMappings)) {
                if ($class->fieldMappings[$propName]['type'] === 'decimal') {
                    if ($orgValue == $actualValue) {
                        continue;
                    }
                }
            } 
Originally created by @Bordovsky on GitHub (Apr 8, 2016). Originally assigned to: @Ocramius on GitHub. Hi. I would like to make pull request, but when I tried add my branch/code I got 403 response. I will add code here, since it is nothing huge. I hope you don't mind. When working around decimals in php, they change type. Since doctrine see them as strings and we works with them as numbers. It leads into unnecessary change set values in persisting which doesn't do any real change. Workaround in entities seems difficult so I added few lines of code into UnitOfWork and it works, and pass all tests. I suppose others wouldn't mind if change set contained only real changes. Here is code, it belongs on line 665 in UnitOfWork.php: ``` if (array_key_exists($propName,$class->fieldMappings)) { if ($class->fieldMappings[$propName]['type'] === 'decimal') { if ($orgValue == $actualValue) { continue; } } } ```
admin added the Invalid label 2026-01-22 14:57:59 +01:00
admin closed this issue 2026-01-22 14:58:00 +01:00
Author
Owner

@Ocramius commented on GitHub (Apr 8, 2016):

The field is supposed to be a string, unless you actually can afford losing precision.

Comparing types always happens with strict comparison: if you want to avoid an update, then cast the value back to a string or use a custom type (if you can afford playing with dangerous precision).

@Ocramius commented on GitHub (Apr 8, 2016): The field is supposed to be a string, unless you actually can afford losing precision. Comparing types always happens with strict comparison: if you want to avoid an update, then cast the value back to a `string` or use a custom type (if you can afford playing with dangerous precision).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5086