This project is archived and is in readonly mode.

#5626 ✓resolved
Ryan Wallace

ActiveRecord generates invalid SQL when eager loading a hmt association with an order

Reported by Ryan Wallace | September 13th, 2010 @ 04:26 PM | in 2.3.10

Given:

class Author < ActiveRecord::Base
  has_many :posts
  has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
end

Running:

Author.first(:include => :comments_desc)

Will generate the following invalid SQL:

SELECT "posts".* FROM "posts" WHERE ("posts".author_id = 1)  ORDER BY comments.id DESC

This issue was not present in 2.3.5 but occurs in 2.3.9.

I've attached a failing test case which demonstrates this issue.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages