Module: ArLazyPreload::Relation

Defined in:
lib/motor/active_record_utils/ar_lazy_preload_patch.rb

Instance Method Summary collapse

Instance Method Details

#preload_associations(records) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/motor/active_record_utils/ar_lazy_preload_patch.rb', line 6

def preload_associations(records)
  preload = preload_values
  preload += includes_values unless eager_loading?
  scope = strict_loading_value ? ActiveRecord::Relation::StrictLoadingScope : nil
  preload.each do |associations|
    preloader_associations = ActiveRecord::Associations::Preloader.new(records: records,
                                                                       associations: associations,
                                                                       scope: scope).call

    preloader_associations.each do |preloader_association|
      handle_preloaded_records(preloader_association.preloaded_records)
    end
  end
end