Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Avoid updating updated_at when counter_cache column is updated. #44

Merged
merged 1 commit into from

2 participants

@asifkalam

Updating the counter_cache should not update the updated_at timestamp. This will cause creation of child records to make parent records seem updated, when they are actually not.

@sferik sferik merged commit bdd7a05 into charlotte-ruby:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 4, 2012
  1. Avoid updating timestamp when updating counter_cache.

    Asif S Kalam authored
This page is out of date. Refresh to see the latest.
View
3  app/models/impressionist/impressionable.rb
@@ -38,7 +38,8 @@ def update_impressionist_counter_cache
cache_options = self.class.impressionist_counter_cache_options
column_name = cache_options[:column_name].to_sym
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
- update_attribute(column_name, count)
+ old_count = send(column_name) || 0
+ self.class.update_counters(id, column_name => (count - old_count))
end
# OLD METHODS - DEPRECATE IN V0.5
View
7 test_app/spec/models/counter_caching_spec.rb
@@ -38,6 +38,13 @@
@widget.reload
}.should change(@widget, :impressions_count).from(0).to(1)
end
+
+ it "should not update the timestamp on the impressable" do
+ lambda {
+ @widget.impressions.create(:request_hash => 'abcd1234')
+ @widget.reload
+ }.should_not change(@widget, :updated_at)
+ end
end
end
Something went wrong with that request. Please try again.