<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,9 @@
+2009-03-11 Adrian Mugnolo &lt;adrian@randomba.org&gt;
+  * Fix a critical problem with image updates breaking when used together with
+    Rails' partial updates feature (now &quot;on&quot; by default). Thanks to Juan
+    Schwindt &lt;juan@schwindt.org&gt; for the report.
+  * Replaced a raw SQL call with update_all.
+
 2008-10-22 Gerrit Keiser and Tricycle Developments
   * Added option to not delete images on destroy
   * Made thumbnail name separator configurable</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -58,7 +58,7 @@ require 'has_image/view_helpers'
 # directory. Add something like this to your config/environments/test.rb:
 #
 #   config.after_initialize do
-#     MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, &quot;tmp&quot;) 
+#     MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, &quot;tmp&quot;)
 #   end
 #
 # If you want to stub out calls to has_image so that your tests don't do
@@ -254,9 +254,11 @@ module HasImage
           storage.remove_images(self, send(has_image_options[:column]))
           # The record will be frozen if we're being called after destroy.
           unless frozen?
-            # Resorting to SQL here to avoid triggering callbacks. There must be
-            # a better way to do this.
-            self.connection.execute(&quot;UPDATE #{self.class.table_name} SET #{has_image_options[:column]} = NULL WHERE id = #{id}&quot;)          
+            # FIXME: although this is cleaner now, it introduces a new issue
+            # with partial updates.
+            updates    = &quot;#{connection.quote_column_name(has_image_options[:column])} = NULL&quot;
+            conditions = &quot;#{connection.quote_column_name(self.class.primary_key)} = #{connection.quote(id)}&quot;
+            self.class.update_all(updates, conditions)
             self.send(&quot;#{has_image_options[:column]}=&quot;, nil)
           end
         rescue Errno::ENOENT
@@ -297,6 +299,12 @@ module HasImage
     private
 
     def populate_attributes
+      # FIXME: this is a quick and dirty work around for image updates
+      # breaking when running with Rails' partial updates. This is originated
+      # by the update_all call in the remove_images method which bypasses
+      # ActiveRecord::Dirty attribute change tracking.
+      attribute_will_change!(has_image_options[:column].to_s) if respond_to?(:attribute_will_change!, true)
+
       send(&quot;#{has_image_options[:column]}=&quot;, storage.install_images(self))
       self[:width] = storage.measure(absolute_path, :width) if self.class.column_names.include?('width')
       self[:height] = storage.measure(absolute_path, :height) if self.class.column_names.include?('height')
@@ -304,7 +312,6 @@ module HasImage
       save!
     end
 
-
   end
 
   module ModelClassMethods</diff>
      <filename>lib/has_image.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>56899674dc40372d7280124c934186ef6352475e</id>
    </parent>
  </parents>
  <author>
    <name>Adrian Mugnolo</name>
    <email>adrian@mugnolo.com</email>
  </author>
  <url>http://github.com/norman/has_image/commit/d2c69feaa201567f69be5a15c0a06d7b88053603</url>
  <id>d2c69feaa201567f69be5a15c0a06d7b88053603</id>
  <committed-date>2009-03-11T14:52:09-07:00</committed-date>
  <authored-date>2009-03-11T14:52:09-07:00</authored-date>
  <message>Fix a problem related to partial updates.</message>
  <tree>88b098db162a3bfffa9e71e306297f45d16cba17</tree>
  <committer>
    <name>Adrian Mugnolo</name>
    <email>adrian@mugnolo.com</email>
  </committer>
</commit>
