When using a many to many relation with a join model and eager loading duplicate table aliases are created. In the following case:
class Post < ActiveRecord::Base
has_many :readers
has_many :people, :through => :readers
end
class Reader < ActiveRecord::Base
belongs_to :post
belongs_to :person
end
class Person < ActiveRecord::Base
has_many :readers
has_many :posts, :through => :readers
end
Eager loading may produce an invalid SQL query that does not alias the join model name. e.g.
@people = Post.find(id).people.find(:all, :include => :posts)
This issue is similar to #8267 but is not identical and is not fixed by the patch for that issue. I have attached a test case.