Skip to content
This repository
Browse code

use attribute methods for finding key values rather than generating m…

…ethod names
  • Loading branch information...
commit e79fae55847506d138a3eca616b0c6e3ee560e26 1 parent 9ca9ff3
Aaron Patterson authored June 11, 2013
6  activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -55,10 +55,10 @@ def belongs_to_counter_cache_after_update(association, reflection)
55 55
 
56 56
           if (@_after_create_counter_called ||= false)
57 57
             @_after_create_counter_called = false
58  
-          elsif self.send("#{foreign_key}_changed?") && !new_record? && Object.const_defined?(name.to_s.camelize)
  58
+          elsif attribute_changed?(foreign_key) && !new_record? && Object.const_defined?(name.to_s.camelize)
59 59
             model = name.to_s.camelize.constantize
60  
-            foreign_key_was = self.send("#{foreign_key}_was")
61  
-            foreign_key = self.send foreign_key
  60
+            foreign_key_was = attribute_was foreign_key
  61
+            foreign_key = attribute foreign_key
62 62
 
63 63
             if foreign_key && model.respond_to?(:increment_counter)
64 64
               model.increment_counter(cache_column, foreign_key)

0 notes on commit e79fae5

Please sign in to comment.
Something went wrong with that request. Please try again.