On May 16, 2014, at 2:35 PM, Lawrence Wu <lawre...@lawrencewu.me> 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

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to