aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 2d2f2297ed..dfde2e6e1d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1237,9 +1237,16 @@ module ActiveRecord #:nodoc:
end
def find_every(options)
- records = scoped?(:find, :include) || options[:include] ?
- find_with_associations(options) :
- find_by_sql(construct_finder_sql(options))
+ include_associations = merge_includes(scope(:find, :include), options[:include])
+
+ if include_associations.any? && references_eager_loaded_tables?(options)
+ records = find_with_associations(options)
+ else
+ records = find_by_sql(construct_finder_sql(options))
+ if include_associations.any?
+ preload_associations(records, include_associations)
+ end
+ end
records.each { |record| record.readonly! } if options[:readonly]