I have the following code:
class Post < ActiveRecord::Base
default_scope :order => 'created_at DESC'
has_many :replies, :class_name => 'Post', :foreign_key=>"parent_id", :order=>"created_at ASC"
end
In Rails 2.3.8 when I was retrieving the replies (i.e.
post.replies) I got them in the correct order. But in
Rails 3.0.4 I get them in descending order, as if the order clause
in the has_many association has no effect. When I checked the SQL
resulting from this call I saw that it was generating the
following:
SELECT `posts`.* FROM `posts` WHERE (`posts`.parent_id = 514) ORDER BY created_at desc, created_at ASC
While this behavior makes sense when the order is using two
different fields, in case it is the same field it should just
override the one in default scope.
This behavior is somewhat similar to ticket #2346, but
there it was referencing Rails 2.3 and I wasn't it is exactly the
same.