3 ms·
I don't know Rails Active Record. But if the ORM is anything like others I am more familiar with (Django / Python or Linq / C#) can't you do a join and just hav
by keltex 4y ago
I don't know Rails Active Record. But if the ORM is anything like others I am more familiar with (Django / Python or Linq / C#) can't you do a join and just have a single query? Or use raw SQL if performance is an issue?
- deleted 4y ago[deleted]
- n_e 4y agoI don't know ActiveRecord either, but it appears so https://guides.rubyonrails.org/active_record_querying.html#joining-a-single-association https://guides.rubyonrails.org/active_record_querying.html#j...
- acjohnson55 4y agoThe problem tends to come up when you pass models around and subsequent logic traverses relationships. It's fundamentally an issue of treating Active Record-style models as though they were in-memory objects.
- jbverschoor 4y agoNo it's not. If one forehand you do not know which "object graph" you need, you'll run in this problem no matter what the underlying tech is. At least some with ORMs you can specify afterwards (when passing the activerecords) that you want to have prefetched (inner or outer joins, caching). Sometimes it's done automatically, because you can simply detect when you're in an N+1 query loop.