diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 14:55:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 14:55:29 -0700 |
commit | 438e172a4598736e3ed1b3d6eddbe2396651a0ef (patch) | |
tree | 124a9399eb8746ba69bdb6883008df1fb3285559 /activerecord/lib/active_record | |
parent | 75beb6c7c3173ba78f212cfeccaa172beccf4e92 (diff) | |
download | rails-438e172a4598736e3ed1b3d6eddbe2396651a0ef.tar.gz rails-438e172a4598736e3ed1b3d6eddbe2396651a0ef.tar.bz2 rails-438e172a4598736e3ed1b3d6eddbe2396651a0ef.zip |
association builder is no longer needed for counter cache, so remove it
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index a2f4758b57..2755eb7c6d 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -29,7 +29,7 @@ module ActiveRecord::Associations::Builder return if mixin.method_defined? :belongs_to_counter_cache_after_create mixin.class_eval do - def belongs_to_counter_cache_after_create(association, reflection) + def belongs_to_counter_cache_after_create(reflection) if record = send(reflection.name) cache_column = reflection.counter_cache_column record.class.increment_counter(cache_column, record.id) @@ -37,7 +37,7 @@ module ActiveRecord::Associations::Builder end end - def belongs_to_counter_cache_before_destroy(association, reflection) + def belongs_to_counter_cache_before_destroy(reflection) foreign_key = reflection.foreign_key.to_sym unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key record = send reflection.name @@ -48,7 +48,7 @@ module ActiveRecord::Associations::Builder end end - def belongs_to_counter_cache_after_update(association, reflection) + def belongs_to_counter_cache_after_update(reflection) foreign_key = reflection.foreign_key cache_column = reflection.counter_cache_column @@ -72,18 +72,17 @@ module ActiveRecord::Associations::Builder def add_counter_cache_callbacks(model, reflection) cache_column = reflection.counter_cache_column - association = self model.after_create lambda { |record| - record.belongs_to_counter_cache_after_create(association, reflection) + record.belongs_to_counter_cache_after_create(reflection) } model.before_destroy lambda { |record| - record.belongs_to_counter_cache_before_destroy(association, reflection) + record.belongs_to_counter_cache_before_destroy(reflection) } model.after_update lambda { |record| - record.belongs_to_counter_cache_after_update(association, reflection) + record.belongs_to_counter_cache_after_update(reflection) } klass = reflection.class_name.safe_constantize |