# File lib/active_record/attribute_methods/dirty.rb, line 90
90: def clone_with_time_zone_conversion_attribute?(attr, old)
91: old.class.name == "Time" && time_zone_aware_attributes && !skip_time_zone_conversion_for_attributes.include?(attr.to_sym)
92: end
# File lib/active_record/attribute_methods/dirty.rb, line 74
74: def field_changed?(attr, old, value)
75: if column = column_for_attribute(attr)
76: if column.number? && column.null && (old.nil? || old == 0) && value.blank?
77: # For nullable numeric columns, NULL gets stored in database for blank (i.e. '') values.
78: # Hence we don't record it as a change if the value changes from nil to ''.
79: # If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
80: # be typecast back to 0 (''.to_i => 0)
81: value = nil
82: else
83: value = column.type_cast(value)
84: end
85: end
86:
87: old != value
88: end
# File lib/active_record/attribute_methods/dirty.rb, line 64
64: def update(*)
65: if partial_updates?
66: # Serialized attributes should always be written in case they've been
67: # changed in place.
68: super(changed | (attributes.keys & self.class.serialized_attributes.keys))
69: else
70: super
71: end
72: end
Wrap write_attribute to remember original attribute value.
# File lib/active_record/attribute_methods/dirty.rb, line 46
46: def write_attribute(attr, value)
47: attr = attr.to_s
48:
49: # The attribute already has an unsaved change.
50: if attribute_changed?(attr)
51: old = @changed_attributes[attr]
52: @changed_attributes.delete(attr) unless field_changed?(attr, old, value)
53: else
54: old = clone_attribute_value(:read_attribute, attr)
55: # Save Time objects as TimeWithZone if time_zone_aware_attributes == true
56: old = old.in_time_zone if clone_with_time_zone_conversion_attribute?(attr, old)
57: @changed_attributes[attr] = old if field_changed?(attr, old, value)
58: end
59:
60: # Carry on.
61: super(attr, value)
62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.