Permalink
Browse files

Checked in the proper version of const_missing

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@236 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5df6128 commit 2e3106b617ada84a8932e80f98c5a95e088c4698 @dhh dhh committed Dec 20, 2004
Showing with 17 additions and 17 deletions.
  1. +17 −17 activerecord/lib/active_record/associations.rb
@@ -4,24 +4,24 @@
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

0 comments on commit 2e3106b

Please sign in to comment.