diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-20 16:57:56 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-20 16:57:56 +0000 |
commit | 2e3106b617ada84a8932e80f98c5a95e088c4698 (patch) | |
tree | 324b7c59b2d043b76063dc877d3631a1317de4ba /activerecord/lib | |
parent | 5df6128bfdb7abaedc0a4f28aba1032a263b9a8a (diff) | |
download | rails-2e3106b617ada84a8932e80f98c5a95e088c4698.tar.gz rails-2e3106b617ada84a8932e80f98c5a95e088c4698.tar.bz2 rails-2e3106b617ada84a8932e80f98c5a95e088c4698.zip |
Checked in the proper version of const_missing
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@236 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0f40cce32c..11dd89ae43 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -4,24 +4,24 @@ require 'active_record/associations/has_and_belongs_to_many_association' require 'active_record/deprecated_associations' -class << Object #:nodoc: - # Make require_association available as a bare method. - unless respond_to?(:require_association) - def require_association(file_name) - ActiveRecord::Base.require_association(file_name) - end - end - - # Use const_missing to autoload associations so we don't have to - # require_association when using single-table inheritance. - unless respond_to?(:pre_association_const_missing) - alias_method :pre_association_const_missing, :const_missing +unless Object.respond_to?(:require_association) + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } +end - def const_missing(class_id) - begin - require_association(Inflector.underscore(Inflector.demodulize(class_id.to_s))) - rescue LoadError - pre_association_const_missing(class_id) +class Object + class << self + # Use const_missing to autoload associations so we don't have to + # require_association when using single-table inheritance. + unless respond_to?(:pre_association_const_missing) + alias_method :pre_association_const_missing, :const_missing + + def const_missing(class_id) + begin + require_association(Inflector.underscore(Inflector.demodulize(class_id.to_s))) + return Object.const_get(class_id) if Object.const_get(class_id).ancestors.include?(ActiveRecord::Base) + rescue LoadError + pre_association_const_missing(class_id) + end end end end |