aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-06-11 12:01:29 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-06-11 12:01:29 -0700
commitbf28422cbda9068afb900020fa6911afd01963e1 (patch)
tree7c2048796f30e45c9613c53b997c35122a5eec1e /activerecord/lib/active_record/associations/builder
parente79fae55847506d138a3eca616b0c6e3ee560e26 (diff)
downloadrails-bf28422cbda9068afb900020fa6911afd01963e1.tar.gz
rails-bf28422cbda9068afb900020fa6911afd01963e1.tar.bz2
rails-bf28422cbda9068afb900020fa6911afd01963e1.zip
check whether the association is constructible rather than checking constants
Diffstat (limited to 'activerecord/lib/active_record/associations/builder')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index aaef86d5b9..783f4e857a 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -55,10 +55,10 @@ module ActiveRecord::Associations::Builder
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)