Permalink
Browse files

association builder is no longer needed for counter cache, so remove it

  • Loading branch information...
1 parent 75beb6c commit 438e172a4598736e3ed1b3d6eddbe2396651a0ef @tenderlove tenderlove committed Oct 2, 2013
Showing with 6 additions and 7 deletions.
  1. +6 −7 activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -29,15 +29,15 @@ def add_counter_cache_methods(mixin)
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)
@_after_create_counter_called = true
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 @@ def belongs_to_counter_cache_before_destroy(association, reflection)
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 @@ def belongs_to_counter_cache_after_update(association, reflection)
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

0 comments on commit 438e172

Please sign in to comment.