Setting null value to a property that is already null causes it to be "dirty"
bretto36 opened this issue · comments
I've found an issue where i have a Contact that is being returned with a null last name.
If i write $contact->setLastName(null) it marks it as dirty even though the values are the same. The function at the bottom is the problem.
Would it be feasible to change this to allow it to compare the value more accurately? I'm happy to do the PR, just want the feedback before i do the work
something like
$currentValue = isset($this->_data[$property]) ? $this->_data[$property] : null;
if ($currentValue !== $value) {
Original Function
protected function propertyUpdated($property, $value)
{
if (! isset($this->_data[$property]) || $this->_data[$property] !== $value) {
//If this object can update itself, set its own dirty flag, otherwise, set its parent's.
if (count(array_intersect($this::getSupportedMethods(), [Request::METHOD_PUT, Request::METHOD_POST])) > 0) {
//Object can update itself
$this->setDirty($property);
} else {
//Object can't update itself, so tell its parents
foreach ($this->_associated_objects as $parent_property => $object) {
$object->setDirty($parent_property);
}
}
}
}
Yep, I think that's perfectly fine! Thanks