diff options
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index a1b6606e3e..668506c01a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -664,11 +664,23 @@ 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) + relation = construct_finder_arel(options) + include_associations = merge_includes(scope(:find, :include), options[:include]) + + if include_associations.any? + if references_eager_loaded_tables?(options) + relation.eager_load(include_associations) + else + 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 @@ -1719,7 +1731,6 @@ module ActiveRecord #:nodoc: relation = relation.readonly if options[:readonly] relation - end def construct_finder_sql(options, scope = scope(:find)) |