From 964b67dd0eb2b43cc8097492c52ce777c534cd11 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 4 Mar 2006 15:11:17 +0000 Subject: Make counter_cache work with polymorphic belongs_to git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3756 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0c7e647628..f841d50288 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -506,22 +506,22 @@ module ActiveRecord EOF end - if options[:counter_cache] - module_eval( - "after_create '#{reflection.class_name}.increment_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + - " unless #{reflection.name}.nil?'" - ) - - module_eval( - "before_destroy '#{reflection.class_name}.decrement_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + - " unless #{reflection.name}.nil?'" - ) - end - # deprecated api deprecated_has_association_method(reflection.name) deprecated_association_comparison_method(reflection.name, reflection.class_name) end + + if options[:counter_cache] + module_eval( + "after_create '#{reflection.name}.class.increment_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + + " unless #{reflection.name}.nil?'" + ) + + module_eval( + "before_destroy '#{reflection.name}.class.decrement_counter(\"#{self.to_s.underscore.pluralize + "_count"}\", #{reflection.primary_key_name})" + + " unless #{reflection.name}.nil?'" + ) + end end # Associates two classes via an intermediate join table. Unless the join table is explicitly specified as -- cgit v1.2.3