diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-17 10:23:13 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-17 10:23:13 -0800 |
commit | 5f07953f36439e58fac07b1255d6141121b27817 (patch) | |
tree | ae9b9b89dc69452f046e747e192cc37abb2789ed /activerecord/lib | |
parent | 18a62acd6d89642fa05389731d122352ea6d7eaa (diff) | |
parent | ee013a503db125b8be54daec7096e2d26bb6228c (diff) | |
download | rails-5f07953f36439e58fac07b1255d6141121b27817.tar.gz rails-5f07953f36439e58fac07b1255d6141121b27817.tar.bz2 rails-5f07953f36439e58fac07b1255d6141121b27817.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.rb | 3 |
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({ |