Method: QueryHelper::Associations.preload_associations

Defined in:
lib/query_helper/associations.rb

.preload_associations(payload:, preload: []) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/query_helper/associations.rb', line 21

def self.preload_associations(payload:, preload: [])
  begin
    # Preloader have been changed in Rails 7, which is giving error on upgrade.
    # This should be updated to latest API once all repos have been upgraded to Rails 7
    ActiveRecord::Associations::Preloader.new.preload(payload, preload)
  rescue
    ActiveRecord::Associations::Preloader.new(records: payload, associations: preload).call
  end
end