rails/rails — pull request #10164 by neerajdotname (2013-04-10 13:02:59+00:00)
Title: While merging relations preserve context for joins

Fixes #3002. Also see #5494.

class Comment < ActiveRecord::Base
belongs_to :post
end

class Author < ActiveRecord::Base
has_many :posts
end

class Post < ActiveRecord::Base
belongs_to :author
has_many :comments
end

`Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would
fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.

It is failing because `all` is being called on relation which looks like this after all the merging:
`{:joins=>[:post, :author], :where=>[#