@@ -77,8 +77,8 @@ def update(*)
77
77
78
78
def _field_changed? ( attr , old , value )
79
79
if column = column_for_attribute ( attr )
80
- if numeric_changes_from_nil_to_empty_string ?( column , old , value ) ||
81
- numeric_changes_from_zero_to_string ?( column , old , value )
80
+ if column . number? && ( changes_from_nil_to_empty_string ?( column , old , value ) ||
81
+ changes_from_zero_to_string ?( column , old , value ) )
82
82
value = nil
83
83
else
84
84
value = column . type_cast ( value )
@@ -88,17 +88,17 @@ def _field_changed?(attr, old, value)
88
88
old != value
89
89
end
90
90
91
- def numeric_changes_from_nil_to_empty_string ?( column , old , value )
91
+ def changes_from_nil_to_empty_string ?( column , old , value )
92
92
# For nullable numeric columns, NULL gets stored in database for blank (i.e. '') values.
93
93
# Hence we don't record it as a change if the value changes from nil to ''.
94
94
# If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
95
95
# be typecast back to 0 (''.to_i => 0)
96
- column . number? && column . null && ( old . nil? || old == 0 ) && value . blank?
96
+ column . null && ( old . nil? || old == 0 ) && value . blank?
97
97
end
98
98
99
- def numeric_changes_from_zero_to_string ?( column , old , value )
100
- # For numeric columns with old 0 and value non-empty string
101
- column . number? && old == 0 && value != '0' && ! value . blank ? && ! old . nil?
99
+ def changes_from_zero_to_string ?( column , old , value )
100
+ # For columns with old 0 and value non-empty string
101
+ old == 0 && value . present ? && value != '0'
102
102
end
103
103
end
104
104
end
0 commit comments