Skip to content

Commit e973fa4

Browse files
committed
bug symfony#10151 [Form] Update DateTime objects only if the actual value has changed (peterrehm)
This PR was squashed before being merged into the 2.3 branch (closes symfony#10151). Discussion ---------- [Form] Update DateTime objects only if the actual value has changed | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Right now the Form component replaces DateTime fields with new Objects, therefore the hash is changing. This leads to unnecessary database updated when working with doctrine. With this patch the DateTime object of the actual entity is only replaced if the value has been changed. Commits ------- 1f22d3a [Form] Update DateTime objects only if the actual value has changed
2 parents c476d13 + 1f22d3a commit e973fa4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function mapFormsToData($forms, &$data)
8181
// Write-back is disabled if the form is not synchronized (transformation failed),
8282
// if the form was not submitted and if the form is disabled (modification not allowed)
8383
if (null !== $propertyPath && $config->getMapped() && $form->isSubmitted() && $form->isSynchronized() && !$form->isDisabled()) {
84+
85+
// If the field is of type DateTime and the data is the same skip the update to
86+
// keep the original object hash
87+
if ($form->getData() instanceof \DateTime && $form->getData() == $this->propertyAccessor->getValue($data, $propertyPath)) {
88+
continue;
89+
}
90+
8491
// If the data is identical to the value in $data, we are
8592
// dealing with a reference
8693
if (!is_object($data) || !$config->getByReference() || $form->getData() !== $this->propertyAccessor->getValue($data, $propertyPath)) {

0 commit comments

Comments
 (0)