Skip to content

Commit

Permalink
check whether the association is constructible rather than checking c…
Browse files Browse the repository at this point in the history
…onstants
  • Loading branch information
tenderlove committed Jun 11, 2013
1 parent e79fae5 commit bf28422
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -55,10 +55,10 @@ def belongs_to_counter_cache_after_update(association, reflection)

if (@_after_create_counter_called ||= false)
@_after_create_counter_called = false
elsif attribute_changed?(foreign_key) && !new_record? && Object.const_defined?(name.to_s.camelize)
model = name.to_s.camelize.constantize
elsif attribute_changed?(foreign_key) && !new_record? && association.constructable?
model = reflection.klass
foreign_key_was = attribute_was foreign_key
foreign_key = attribute foreign_key
foreign_key = attribute foreign_key

if foreign_key && model.respond_to?(:increment_counter)
model.increment_counter(cache_column, foreign_key)
Expand Down

0 comments on commit bf28422

Please sign in to comment.