A few fixes to eager loading issues

Hey all,

I'd really appreciate some eyes on https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5845-activerecord-3-eager-loading-fail#ticket-5845-19. There's a small issue in Rails 3 eager loading, and this ticket has an accompanying patch.

Sssociations that show up twice in a Relation chain like:

  Article.includes(:comments).includes(:comments => :moderations)

will show up twice in the JoinDependency's join_parts but only once in the query that gets run. This wreaks all kinds of fun havoc with the select statement that gets used in construct_relation_for_association_find, since it will try to select from both copies of the table.

One solution (the one I implemented in the patch) is to ensure that the JoinDependency only joins each association once. This seems to be in keeping with the intended functionality, based on includes_values being "uniq"ed elsewhere. Naturally, a uniq won't catch a situation as described above, since includes_values contains a symbol, :comments, and a hash, {:comments => :moderations}.

Thanks in advance!

Hey Ernie,

I'll take a look in the next few days. :slight_smile: