Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting null value to a property that is already null causes it to be "dirty" #903

Closed
bretto36 opened this issue Nov 27, 2023 · 1 comment

Comments

@bretto36
Copy link
Contributor

bretto36 commented Nov 27, 2023

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);
                }
            }
        }
    }
@calcinai
Copy link
Owner

calcinai commented Dec 3, 2023

Yep, I think that's perfectly fine! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants