I agree with Matt on this subject. Even if we could come up with useful heuristics, we would not deprecate includes, eager_load and preload. There are always situations you can't detect. Also I wouldn't want to use that feature on some of my apps. It can be crucial what Query is executed and such magic code would make it impossible to control.
Cheers, -- Yves On Sunday, May 18, 2014 9:57:05 PM UTC+2, Matt jones wrote: > > > On May 16, 2014, at 2:35 PM, Lawrence Wu <[email protected]<javascript:>> > wrote: > > > I'd like to deprecate methods like includes and eager_load in Rails > since I think it is possible to automatically detect when they are needed. > Ideally the developer could know very little about how databases work and > still get very efficient queries using just the ORM. What do other people > think? > > I’m not terribly convinced that there’s a useful heuristic to > automatically make the right choices for eager-loading, since the right > associations to load are typically driven by what the code does with the > results. > > For instance, this code fragment should either use something different > than `present?` or should use an eager-load, but the right choice depends > on what happens after the records are loaded: > > @posts.each do |post| > # present? will cause the comments association to load > if post.comments.present? > # do something > # if post.comments is referenced here, it should have been > eager-loaded > # if it isn’t referenced, the present? should really be changed to > exists? or similar > end > end > > Even if such a heuristic existed, it would still be wrong some of the time > - so things like `includes` and `eager_load` would still be needed to > specify the correct behavior in those cases. > > It’s definitely worth discussing, but it’s going to (IMO) face a pretty > steep climb to success. > > —Matt Jones > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
