diff options
author | Arthur Neves <arthurnn@gmail.com> | 2014-05-24 14:03:30 -0400 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-05-24 14:55:20 -0400 |
commit | 09ac448a8eff73ffb7a3f683207802e8cb1f6d0b (patch) | |
tree | 668528eedc99f79d91431c7b7dd6acccd42d5221 /activerecord/lib/active_record/counter_cache.rb | |
parent | e2bd0eb758100a5d6f55201318809a7ed7b37040 (diff) | |
download | rails-09ac448a8eff73ffb7a3f683207802e8cb1f6d0b.tar.gz rails-09ac448a8eff73ffb7a3f683207802e8cb1f6d0b.tar.bz2 rails-09ac448a8eff73ffb7a3f683207802e8cb1f6d0b.zip |
Merge pull request #15210 from arthurnn/fix_hbtm_reflection
Fix habtm reflection
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/counter_cache.rb
activerecord/lib/active_record/reflection.rb
activerecord/test/cases/reflection_test.rb
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index 71e176a328..874a7c2f2d 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -20,7 +20,7 @@ module ActiveRecord def reset_counters(id, *counters) object = find(id) counters.each do |counter_association| - has_many_association = reflect_on_association(counter_association.to_sym) + has_many_association = _reflect_on_association(counter_association.to_sym) unless has_many_association has_many = reflect_on_all_associations(:has_many) has_many_association = has_many.find { |association| association.counter_cache_column && association.counter_cache_column.to_sym == counter_association.to_sym } @@ -34,8 +34,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 && e.options[:counter_cache].present? } + reflection = child_class._reflections.values.find { |e| :belongs_to == e.macro && 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({ |