rails/rails — pull request #8403 by senny (2012-12-02 20:35:23+00:00)
Title: Do not instantiate intermediate AR objects when eager loading.

There are eager-loading queries that Active Record performs in two steps.

1. Fetch the ID of the relevant records
1. Perform the actual select to instantiate AR objects

Currently step one also instantiated intermediate ActiveRecord objects just to pick the ID from them. This changes fetches the IDs using `select_all`, which does not instante objects.

The intermediate objects were a problem because the `after_find` callback was triggered twice. Also I think it does not make sense to instantiate objects that we don't actually need.

This is a fix for #3313

I'm not sure if my test-case is very helpful. It was the best I could come up with to illustrate the problem.