I''m posting this to confirm that what I''m doing should work
before I
log an official bug.
I have two tables, "folders" and "messages" with a habtm
relationship
between them. In folders, the relationship is defined as:
has_and_belongs_to_many :messages, :order => "date DESC"
I also have a FeedFolder model, which is a subclass of Folder.
When, in a controller, I do a find as follows:
@folder = FeedFolder.find @params["id"], :include =>
[:messages]
the find returns the correct results, but @folders.messages is not
ordered correctly. Looking at the SQL in development.log, I see:
SELECT ... FROM folders LEFT OUTER JOIN folders_messages ON
folders_messages.folder_id = folders.id LEFT OUTER JOIN messages ON
folders_messages.message_id = messages.id WHERE folders.id =
''11'' AND
(folders.type = ''FeedFolder'' )
Note the lack of an ORDER BY clause.
I can force the correct result by doing:
@folder = FeedFolder.find @params["id"], :include =>
[:messages], :order => "messages.date DESC"
If this is me stuffing something up rather than a bug then feel free
to put me in my place. :)
Cheers,
Pete Yandell