consider this code:
# in Rails 6.1
def preload(resource, relations)
ActiveRecord::Associations::Preloader.new.preload(resource, relations)
end
So: I want to change that for compatibility with Rails 7 so I wrote this:
def preload(resource, relations)
ActiveRecord::Associations::Preloader.new(records: resource, associations: relations)
end
Did I do a right thing? because .preload(resource, relations) is not exit in Rails 7 anymore. if you have any other suggestion I'm so looking forward for it
You're almost there. It looks like this works:
ActiveRecord::Associations::Preloader.new(
records: [resource].flatten, # in case if resource is a single ApplicationRecord object
associations: relations
).call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With