Ralph::EagerLoading::Preloader
Preloader - handles the separate-query preloading strategy
This is the recommended strategy for most use cases. It executes N+1 queries as 2 queries using IN clause batching.
Example:
authors = Author.all
Preloader.preload(authors, :posts)
# Now authors.each { |a| a.posts } won't trigger additional queries
Class methods
Preload associations on a collection of models
Supports various include specifications:
- Symbol: preload(:posts)
- Array: preload([:posts, :comments])
- Hash: preload({posts: :comments})