Project

General

Profile

Actions

Defect #11170

closed

Topics sort order is broken in Redmine 2.x

Added by Vitaly Klimov almost 12 years ago. Updated almost 12 years ago.

Status:
Closed
Priority:
Normal
Category:
Forums
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Because of Rails 3 by default uses order from has_many :order statement before any defined order, messages are always sorted by creation time first regardless of sticky attribute.

To fix it, line 46 in file app/controllers/boards_controller.rb

@topics =  @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
   :include => [:author, {:last_reply => :author}],
   :limit  =>  @topic_pages.items_per_page,
   :offset =>  @topic_pages.current.offset

should be changed to

@topics =  @board.topics.reorder(["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', ')).all(
   :include => [:author, {:last_reply => :author}],
   :limit  =>  @topic_pages.items_per_page,
   :offset =>  @topic_pages.current.offset)
Actions #1

Updated by Etienne Massip almost 12 years ago

Why not move the sort order to the has_many association declaration in source:/tags/2.0.2/app/models/board.rb#L21?

Actions #2

Updated by Vitaly Klimov almost 12 years ago

Etienne Massip wrote:

Why not move the sort order to the has_many association declaration in source:/tags/2.0.2/app/models/board.rb#L21?

I am not sure why topics are sorted by creation time by default, but if it is does not matter - then yes, moving sticky sort order to association will simplify things a bit.

Actions #3

Updated by Jean-Philippe Lang almost 12 years ago

  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang
  • Target version set to 2.0.3
  • Resolution set to Fixed

Fixed in r9836, thanks for pointing this out.
We do not always want the messages in the same order (eg. board display vs. atom feed), so having this handled by the association sort order is not a better solution.

Actions #4

Updated by Jean-Philippe Lang almost 12 years ago

  • Status changed from Resolved to Closed

Merged.

Actions

Also available in: Atom PDF