diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 16:14:20 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 16:14:20 +0000 |
commit | 8e1f1ee44241838c2b701ad2622d98c9c41ea268 (patch) | |
tree | 2e9613082d40152c0303f5b95bdd238cd7a1b36f /activerecord/lib/active_record/associations.rb | |
parent | b141bdbb32cb58e493e6f52e4f1baa2a9d28680d (diff) | |
download | rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.tar.gz rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.tar.bz2 rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.zip |
Moved require_association to associations.rb and added methods for resetting the inheritable attributes on subclasses
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@125 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 6f6da10a01..6ba7b80102 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -3,6 +3,10 @@ require 'active_record/associations/has_many_association' require 'active_record/associations/has_and_belongs_to_many_association' require 'active_record/deprecated_associations' +unless Object.respond_to?(:require_association) + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } +end + module ActiveRecord module Associations # :nodoc: def self.append_features(base) @@ -447,6 +451,20 @@ module ActiveRecord deprecated_has_collection_method(association_name) end + # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false. + def require_association(file_name) + if !associations_loaded.include?(file_name) + associations_loaded << file_name + reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name) + end + end + + # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_association is + # called for that dependency it'll be loaded anew. + def reset_associations_loaded + associations_loaded = [] + end + private # Raises an exception if an invalid option has been specified to prevent misspellings from slipping through def validate_options(valid_option_keys, supplied_option_keys) @@ -571,4 +589,4 @@ module ActiveRecord end end end -end +end
\ No newline at end of file |