From c01c21b31d590f7e8d12e3ae083fcdf0f0c6fd54 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 1 Sep 2009 15:36:09 -0300 Subject: Added association preload to relation. --- activerecord/lib/active_record/base.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 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 402d68c36e..1c12189e15 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -664,11 +664,28 @@ module ActiveRecord #:nodoc: # This is an alias for find(:all). You can pass in all the same arguments to this method as you can # to find(:all) def all(*args) - if args.empty? && !scoped?(:find) - arel_table + options = args.extract_options! + + + if options.empty? #&& !scoped?(:find) + relation = arel_table else - construct_finder_arel(*args) + 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? + relation.preload(include_associations) + # end + end end + relation end # Executes a custom SQL query against your database and returns all the results. The results will -- cgit v1.2.3 From 3747f896a1b727d67e6022001007e5f58b24a267 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 5 Oct 2009 14:39:20 -0300 Subject: Moved relation's test to relation_test. --- activerecord/lib/active_record/base.rb | 3 +-- 1 file changed, 1 insertion(+), 2 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 1c12189e15..2fd3384877 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -667,7 +667,7 @@ module ActiveRecord #:nodoc: options = args.extract_options! - if options.empty? #&& !scoped?(:find) + if options.empty? && !scoped?(:find) relation = arel_table else include_associations = merge_includes(scope(:find, :include), options[:include]) @@ -1751,7 +1751,6 @@ module ActiveRecord #:nodoc: relation = relation.readonly if options[:readonly] relation - end def construct_finder_sql(options, scope = scope(:find)) -- cgit v1.2.3 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