aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-17 10:23:13 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-17 10:23:56 -0800
commit57f73a6bcf3311262172f1f348a1be614596b41a (patch)
tree3b08bf5397cb680f0b20846a8aec3668ea1813dd /activerecord/lib
parent5812c35b881d9f6bca3bae92bb4ab7652f8c40ad (diff)
downloadrails-57f73a6bcf3311262172f1f348a1be614596b41a.tar.gz
rails-57f73a6bcf3311262172f1f348a1be614596b41a.tar.bz2
rails-57f73a6bcf3311262172f1f348a1be614596b41a.zip
Merge pull request #4487 from sarenji/fix-reset-counters
Fix bug where reset_counters resets the wrong counter cache.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index 031918712a..c9c46b8d4f 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -25,9 +25,10 @@ module ActiveRecord
self.name
end
+ foreign_key = has_many_association.foreign_key.to_s
child_class = has_many_association.klass
belongs_to = child_class.reflect_on_all_associations(:belongs_to)
- reflection = belongs_to.find { |e| e.class_name == expected_name }
+ reflection = belongs_to.find { |e| e.foreign_key.to_s == foreign_key }
counter_name = reflection.counter_cache_column
stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({