3 ms·
Modern Ruby on Rails makes this really easy with Strict Loading. https://til.hashrocket.com/posts/l4t5xok8hg-activerecord-strict-loading-in-rails https://til.h
by brightball 3y ago
Modern Ruby on Rails makes this really easy with Strict Loading.
https://til.hashrocket.com/posts/l4t5xok8hg-activerecord-strict-loading-in-rails https://til.hashrocket.com/posts/l4t5xok8hg-activerecord-str...
One of the biggest perks with the association loads is that it avoids joins by default, which can become a scaling barrier as you grow. Instead, it will capture the associated ids, find all of the related records in a single query and then transparently handle everything for you behind the scenes.
Without any optimizations, you'll get essentially 1 query per loaded association rather than the N+1 "one per association per row".
You can always tune things to utilize joins, subqueries and optimize specific cases later but this is a sensible setting that will avoid the vast majority of issues.