aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTim Chater <t.chater@gmail.com>2008-06-17 13:54:03 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-27 21:31:06 -0700
commit1415df8f49a19d469b9e2c15785db32eb312c000 (patch)
treec5921b7638e3ea3e937d489cbb23d3b43169cd4b /activerecord/lib
parent9a25315076bf90c39ab5471fa8d81736a3b2478e (diff)
downloadrails-1415df8f49a19d469b9e2c15785db32eb312c000.tar.gz
rails-1415df8f49a19d469b9e2c15785db32eb312c000.tar.bz2
rails-1415df8f49a19d469b9e2c15785db32eb312c000.zip
Dirty: recognize when an integer changes from zero to blank. [#433 state:resolved]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/dirty.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb
index b32e17e990..a7d767486c 100644
--- a/activerecord/lib/active_record/dirty.rb
+++ b/activerecord/lib/active_record/dirty.rb
@@ -142,9 +142,11 @@ module ActiveRecord
def field_changed?(attr, old, value)
if column = column_for_attribute(attr)
- if column.type == :integer && column.null && old.nil?
+ 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
value = column.type_cast(value)