diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-11-14 04:12:48 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-11-14 04:13:45 +0900 |
commit | 28708c7a8a4c9d4b835a0443460c0a38dd69982a (patch) | |
tree | c0ecc4739dc445f689dc48ede4e72ddf9b612982 /activerecord | |
parent | 5b2ea20f562aa09ade8965f72c4075dd79609956 (diff) | |
download | rails-28708c7a8a4c9d4b835a0443460c0a38dd69982a.tar.gz rails-28708c7a8a4c9d4b835a0443460c0a38dd69982a.tar.bz2 rails-28708c7a8a4c9d4b835a0443460c0a38dd69982a.zip |
Avoid `build_preloader` if preloading is not needed
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index ef629dcb3b..8b30a48c1c 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -681,9 +681,10 @@ module ActiveRecord @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, bound_attributes, &block).freeze preload = preload_values - preload += includes_values unless eager_loading? - preloader = build_preloader + preload += includes_values unless eager_loading? + preloader = nil preload.each do |associations| + preloader ||= build_preloader preloader.preload @records, associations end |