Using an objet to represent a complex preload

27-Aug-2021 2458
Sometimes just using preload or includes is not possible… or maybe it is, but you just can’t figure it out how to do it.Maybe you want to preload some records matching two keys, or preload a grouped relation.Maybe you know how to represent the association with a has_many :through, but you need something faster, or to use less memory.In that kind of situations, one thing that you can do is to write a custom object to represent that preload.Here I will try to explain how and when you can do it with an example.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle