Created
June 20, 2009 04:14
-
-
Save dburger/133044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def field_changed?(attr, old, value) | |
if column = column_for_attribute(attr) | |
if column.type == :integer && column.null && (old.nil? || old == 0) | |
# For nullable integer columns, NULL gets stored in database for blank (i.e. '') values. | |
# Hence we don't record it as a change if the value changes from nil to ''. | |
# If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll | |
# be typecast back to 0 (''.to_i => 0) | |
value = nil if value.blank? | |
# else no!!!!!!!!!!! not the else branch | |
# value = column.type_cast(value) | |
end | |
value = column.type_cast(value) | |
end | |
old != value | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment