Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Conflicts:
	activerecord/lib/active_record/counter_cache.rb
  • Loading branch information
spastorino authored and rafaelfranca committed Oct 3, 2012
1 parent 3f0bc97 commit 288885f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions activerecord/lib/active_record/counter_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ def reset_counters(id, *counters)
end

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
Expand Down

0 comments on commit 288885f

Please sign in to comment.