diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-23 15:02:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-23 15:02:43 -0700 |
commit | 844efb2bb0d6e40a2d830727f6bc235b37c3a1b1 (patch) | |
tree | 06e4b1d9fe47a08d647171cb188ac052e94fab6e /activerecord/lib/active_record/relation/delegation.rb | |
parent | f38b5444428f418c4e6377bbb40d7518ea0c61a7 (diff) | |
download | rails-844efb2bb0d6e40a2d830727f6bc235b37c3a1b1.tar.gz rails-844efb2bb0d6e40a2d830727f6bc235b37c3a1b1.tar.bz2 rails-844efb2bb0d6e40a2d830727f6bc235b37c3a1b1.zip |
stop relying on side effects of const_missing
Diffstat (limited to 'activerecord/lib/active_record/relation/delegation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/delegation.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 7ed65a548c..b6f80ac5c7 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -77,12 +77,6 @@ module ActiveRecord relation_class_for(klass).new(klass, *args) end - # This doesn't have to be thread-safe. relation_class_for guarantees that this will only be - # called exactly once for a given const name. - def const_missing(name) - const_set(name, Class.new(self) { include ClassSpecificRelation }) - end - private # Cache the constants in @@subclasses because looking them up via const_get # make instantiation significantly slower. @@ -92,7 +86,13 @@ module ActiveRecord # This hash is keyed by klass.name to avoid memory leaks in development mode my_cache.compute_if_absent(klass_name) do # Cache#compute_if_absent guarantees that the block will only executed once for the given klass_name - const_get("#{name.gsub('::', '_')}_#{klass_name.gsub('::', '_')}", false) + subclass_name = "#{name.gsub('::', '_')}_#{klass_name.gsub('::', '_')}" + + if const_defined?(subclass_name) + const_get(subclass_name) + else + const_set(subclass_name, Class.new(self) { include ClassSpecificRelation }) + end end else ActiveRecord::Relation |