diff options
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 7238f97067..6d3b07a435 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -546,13 +546,15 @@ module ActiveRecord #:nodoc: end # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false. - def require_or_load(file_name) + 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 + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } + # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_or_load is # called for that dependency it'll be loaded anew. def reset_associations_loaded @@ -782,10 +784,16 @@ module ActiveRecord #:nodoc: self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method) end - def require_or_load(file_name) - self.class.require_or_load(file_name) + # 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 + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } + private def create_or_update if new_record? then create else update end |