Skip to content

double field typed records always updated in database even no field value changed #88

@istvanmonoriintland

Description

@istvanmonoriintland

When I have a record with a field using double type. After calling the set method on a double field record row is always updated in the database even if the double value has not changed at all.

Detected symfony version: 1.5.14-dev

After some debugging I found that the _isValueModified method in Record.php does not properly check fields with double types. It matches as a string. Adding the double type check (in_array($type, array('decimal', 'float', 'double') into the condition will eliminate this problem.

    protected function _isValueModified($type, $old, $new)
    {
        if ($new instanceof Doctrine_Expression) {
            return true;
        }

        if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) {
            return false;
        } else if (in_array($type, array('decimal', 'float', 'double')) && is_numeric($old) && is_numeric($new)) {
            return $old * 100 != $new * 100;
        } else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) {
            return $old != $new;
        } else if ($type == 'timestamp' || $type == 'date') {
            $oldStrToTime = @strtotime((string) $old);
            $newStrToTime = @strtotime((string) $new);
            if ($oldStrToTime && $newStrToTime) {
                return $oldStrToTime !== $newStrToTime;
            } else {
                return $old !== $new;
            }
        } else {
            return $old !== $new;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions