diff options
author | Jamis Buck <jamis@37signals.com> | 2006-03-04 15:11:17 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-03-04 15:11:17 +0000 |
commit | 964b67dd0eb2b43cc8097492c52ce777c534cd11 (patch) | |
tree | a7c9df0f71a30dff2d9e9c3b62cc39eaf4c6f7cb /activerecord/lib | |
parent | c0d24778867e8b39c160542923f4ccb6b3f48d30 (diff) | |
download | rails-964b67dd0eb2b43cc8097492c52ce777c534cd11.tar.gz rails-964b67dd0eb2b43cc8097492c52ce777c534cd11.tar.bz2 rails-964b67dd0eb2b43cc8097492c52ce777c534cd11.zip |
Make counter_cache work with polymorphic belongs_to
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3756 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 24 |
1 files changed, 12 insertions, 12 deletions
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 |