3
0 Comments

Complex preloading in Rails with custom scopes

So if you're ever faced the need to define custom associations (e.g. has_many association where the IDs are stored as an array on the parent model) then doing proper preloading - to avoid N+1 queries - becomes a bit of a pain.

The Rails preload and eager_load functionalities are made for standard associations and are not really customisable.

The blog post below presents an alternative way to defining custom scopes when your preloading logic doesn't entirely rely on Active Record associations.

https://www.keypup.io/blog/complex-preloading-strategies-in-rails-using-custom-active-record-scopes

If you have come across this problem, I'd curious to know if you've found other solutions to address it.

Trending on Indie Hackers
Getting first 908 Paid Signups by Spending $353 ONLY. 24 comments I talked to 8 SaaS founders, these are the most common SaaS tools they use 20 comments What are your cold outreach conversion rates? Top 3 Metrics And Benchmarks To Track 19 comments Hero Section Copywriting Framework that Converts 3x 12 comments Join our AI video tool demo, get a cool video back! 12 comments How I Sourced 60% of Customers From Linkedin, Organically 11 comments