diff options
author | Dave Desrochers <dave726@gmail.com> | 2012-02-28 10:20:27 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-08-21 14:10:11 -0300 |
commit | ff0d9b93b9074c479dd6de657c71812f0ac40cbe (patch) | |
tree | dfad842195953c034096ef46e8d0c305f37499aa /activerecord/lib/active_record | |
parent | ce0dd56183d198739638c2cfa7c17f90513a7072 (diff) | |
download | rails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.tar.gz rails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.tar.bz2 rails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.zip |
reset_counters() was crashing when there were multiple belongs_to associations with the same foreign key.
This closes #5200.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index b27a19f89a..c877079b25 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -25,7 +25,7 @@ module ActiveRecord 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.foreign_key.to_s == foreign_key } + reflection = belongs_to.find { |e| e.foreign_key.to_s == foreign_key && e.options[:counter_cache].present? } counter_name = reflection.counter_cache_column stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({ |