diff options
author | Ben Symonds <ben@texperts.com> | 2008-12-08 14:11:55 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-08 15:42:13 -0800 |
commit | 091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8 (patch) | |
tree | 381449412223c67200b9b273a2028f329c339769 /activerecord/lib | |
parent | ebec9d43e262d28d742ff10acd828bad6cbb28ed (diff) | |
download | rails-091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8.tar.gz rails-091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8.tar.bz2 rails-091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8.zip |
Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'
[#1530 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/dirty.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb index ae573799ae..a1760875ba 100644 --- a/activerecord/lib/active_record/dirty.rb +++ b/activerecord/lib/active_record/dirty.rb @@ -151,12 +151,12 @@ module ActiveRecord def field_changed?(attr, old, value) if column = column_for_attribute(attr) - if column.type == :integer && column.null && (old.nil? || old == 0) + if column.type == :integer && column.null && (old.nil? || old == 0) && value.blank? # 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? + value = nil else value = column.type_cast(value) end |