From 65f055a3ed790d41aeca8d4ca7f3771b05cf544f Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 5 Oct 2009 15:24:08 -0300 Subject: Added eager loading support to Relation and ActiveRecord#all. --- activerecord/lib/active_record/base.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'activerecord/lib/active_record/base.rb') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2fd3384877..60e69f020c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -666,23 +666,18 @@ module ActiveRecord #:nodoc: def all(*args) options = args.extract_options! - if options.empty? && !scoped?(:find) relation = arel_table else + relation = construct_finder_arel(options) include_associations = merge_includes(scope(:find, :include), options[:include]) - # if include_associations.any? && references_eager_loaded_tables?(options) - # join_dependency = JoinDependency.new(self, include_associations, options[:joins]) - - # relation = construct_finder_arel_with_included_associations(options, join_dependency) - - # relation.preload(include_associations) - # else - relation = construct_finder_arel(options) - if include_associations.any? + if include_associations.any? + if references_eager_loaded_tables?(options) + relation.eager_load(include_associations) + else relation.preload(include_associations) - # end + end end end relation -- cgit v1.2.3