diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index efa8cf1c42..cfaf566ec4 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -599,9 +599,9 @@ module ActiveRecord preload = preload_values preload += includes_values unless eager_loading? + preloader = ActiveRecord::Associations::Preloader.new preload.each do |associations| - pl = ActiveRecord::Associations::Preloader.new - pl.preload @records, associations + preloader.preload @records, associations end @records.each { |record| record.readonly! } if readonly_value