rails/rails — pull request #12610 by prpetten (2013-10-23 00:46:14+00:00)
Title: Adding Table Context to Order Hash

This commit fixes #12604

Prepend original table name to order hash

With the models

class Post
has_many :comments
scope :dewey, -> { order(subject: :desc) }
end

class Comment
belongs_to :post
end

And records

p1 = Post.create(subject: 'Awesomeness')
p2 = Post.create(subject: 'Zaniness')
c1 = Comment.create(type: 'Cool', post_id: p1.id)
c2 = Comment.create(type: 'Cool', post_id: p2.id)

The call

Comment.where(type: 'Cool').joins(:post).merge(Post.dewey)

Should yield

[c2, c1]