aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-10-03 00:48:28 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2012-10-03 00:48:57 -0300
commite4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d (patch)
tree47670aaab5e352e488532400d91b92037b99173b
parentd56b5dacb1fbaeef9d48d57594b2f1f9c32a21bb (diff)
downloadrails-e4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d.tar.gz
rails-e4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d.tar.bz2
rails-e4e84fee8b9ecd63e1cc7b62beb577f8fe7ce35d.zip
Refactor
-rw-r--r--activerecord/lib/active_record/counter_cache.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index d28cd560d9..57838ff984 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -23,12 +23,11 @@ module ActiveRecord
has_many_association = reflect_on_association(association.to_sym)
if has_many_association.is_a? ActiveRecord::Reflection::ThroughReflection
- foreign_key = has_many_association.through_reflection.foreign_key.to_s
- child_class = has_many_association.through_reflection.klass
- else
- foreign_key = has_many_association.foreign_key.to_s
- child_class = has_many_association.klass
+ has_many_association = has_many_association.through_reflection
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.foreign_key.to_s == foreign_key && e.options[:counter_cache].present? }
counter_name = reflection.counter_cache_column