<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -117,14 +117,7 @@ module ActiveRecord
         # The attribute already has an unsaved change.
         unless changed_attributes.include?(attr)
           old = clone_attribute_value(:read_attribute, attr)
-
-          # Remember the original value if it's different.
-          typecasted = if column = column_for_attribute(attr)
-                         column.type_cast(value)
-                       else
-                         value
-                       end
-          changed_attributes[attr] = old unless old == typecasted
+          changed_attributes[attr] = old if field_changed?(attr, old, value)
         end
 
         # Carry on.
@@ -138,5 +131,20 @@ module ActiveRecord
           update_without_dirty
         end
       end
+
+      def field_changed?(attr, old, value)
+        if column = column_for_attribute(attr)
+          if column.type == :integer &amp;&amp; column.null &amp;&amp; old.nil?
+            # 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 ''.
+            value = nil if value.blank?
+          else
+            value = column.type_cast(value)
+          end
+        end
+
+        old != value
+      end
+
   end
 end</diff>
      <filename>activerecord/lib/active_record/dirty.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,6 +44,16 @@ class DirtyTest &lt; ActiveRecord::TestCase
     assert_nil pirate.catchphrase_change
   end
 
+  def test_nullable_integer_not_marked_as_changed_if_new_value_is_blank
+    pirate = Pirate.new
+
+    [&quot;&quot;, nil].each do |value|
+      pirate.parrot_id = value
+      assert !pirate.parrot_id_changed?
+      assert_nil pirate.parrot_id_change
+    end
+  end
+
   def test_object_should_be_changed_if_any_attribute_is_changed
     pirate = Pirate.new
     assert !pirate.changed?</diff>
      <filename>activerecord/test/cases/dirty_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>73c59638549686fccc749ffd3ac53cb533c5fd61</id>
    </parent>
  </parents>
  <author>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/281edce6db8accc7d4a0e9ab01892631d9d0ebc3</url>
  <id>281edce6db8accc7d4a0e9ab01892631d9d0ebc3</id>
  <committed-date>2008-05-20T12:53:47-07:00</committed-date>
  <authored-date>2008-05-20T12:50:46-07:00</authored-date>
  <message>Ensure nil to '' doesn't get recorded by dirty for nullable integer columns. [#150 state:resolved] [Jason Dew, Pratik]</message>
  <tree>6d56e7bae4636d1cab9da18c8880880206c2bfa1</tree>
  <committer>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
