Sha256: 1c95ce9337bea326dc9736e76db2ac6960d29e8de4390a47f98c2ceda5b0274b
Contents?: true
Size: 794 Bytes
Versions: 1
Compression:
Stored size: 794 Bytes
Contents
module EdgeRider module PreloadAssociations module PreloadAssociationsInstanceMethod def preload_associations(*args) self.class.preload_associations([self], *args) end end def preload_associations(*args) preloader = ActiveRecord::Associations::Preloader if preloader.method_defined?(:preload) # Rails 5 to Rails 6.1 preloader.new.preload(*args) else # Rails 7+ records = args.first associations = args.second options = args[2] || {} preloader.new(records: records, associations: associations, **options).call end end end end ActiveSupport.on_load :active_record do extend(EdgeRider::PreloadAssociations) include(EdgeRider::PreloadAssociations::PreloadAssociationsInstanceMethod) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
edge_rider-2.4.0 | lib/edge_rider/preload_associations.rb |