4 ms·
So you have to be explicit in what to "preload"? How does that differ from specifying an includes on associations for eager loading? It's not saving you any m
by aantix 6y ago
So you have to be explicit in what to "preload"?
How does that differ from specifying an includes on associations for eager loading?
It's not saving you any mental energy; you still have to discern what should and shouldn't be loaded up front.
- dmpk2k 6y agoThe question was regarding N+1. If you're not careful with ActiveRecord, you get that. With Ecto, it's impossible. Ecto has its own drawbacks, but its strong suit is predictability.
- aantix 6y agoN+1 is because lazy loading is by default in ActiveRecord. Because it doesn't know anything about your object graph and what associations are needed, so it just loads data as it's encountered. That's a reasonable default. You add includes as you know more about your data and what associations are needed in specific contexts. Eager loading is an optimization, not a prerequisite.