Index: app/controllers/journals_controller.rb =================================================================== --- app/controllers/journals_controller.rb (revision 17354) +++ app/controllers/journals_controller.rb (working copy) @@ -31,7 +31,7 @@ def index retrieve_query if @query.valid? - @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", + @journals = @query.journals(:order => Arel.sql("#{Journal.table_name}.created_on DESC"), :limit => 25) end @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) Index: app/models/message.rb =================================================================== --- app/models/message.rb (revision 17354) +++ app/models/message.rb (working copy) @@ -19,7 +19,7 @@ include Redmine::SafeAttributes belongs_to :board belongs_to :author, :class_name => 'User' - acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" + acts_as_tree :counter_cache => :replies_count, :order => Arel.sql("#{Message.table_name}.created_on ASC") acts_as_attachable belongs_to :last_reply, :class_name => 'Message' Index: app/models/news.rb =================================================================== --- app/models/news.rb (revision 17354) +++ app/models/news.rb (working copy) @@ -80,7 +80,7 @@ # returns latest news for projects visible by user def self.latest(user = User.current, count = 5) - visible(user).preload(:author, :project).order("#{News.table_name}.created_on DESC").limit(count).to_a + visible(user).preload(:author, :project).order(Arel.sql("#{News.table_name}.created_on DESC")).limit(count).to_a end private Index: app/models/query.rb =================================================================== --- app/models/query.rb (revision 17354) +++ app/models/query.rb (working copy) @@ -787,7 +787,7 @@ def group_by_sort_order if column = group_by_column order = (sort_criteria.order_for(column.name) || column.default_order || 'asc').try(:upcase) - Array(column.sortable).map {|s| "#{s} #{order}"} + Array(column.sortable).map {|s| Arel.sql("#{s} #{order}")} end end Index: app/models/version.rb =================================================================== --- app/models/version.rb (revision 17354) +++ app/models/version.rb (working copy) @@ -317,7 +317,9 @@ def self.fields_for_order_statement(table=nil) table ||= table_name - ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"] + statements = ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"] + statements.map!{|order| Arel.sql(order) } + statements end scope :sorted, lambda { order(fields_for_order_statement) } Index: app/models/wiki_page.rb =================================================================== --- app/models/wiki_page.rb (revision 17354) +++ app/models/wiki_page.rb (working copy) @@ -26,7 +26,7 @@ has_one :content_without_text, lambda {without_text.readonly}, :class_name => 'WikiContent', :foreign_key => 'page_id' acts_as_attachable :delete_permission => :delete_wiki_pages_attachments - acts_as_tree :dependent => :nullify, :order => 'title' + acts_as_tree :dependent => :nullify, :order => Arel.sql('title') acts_as_watchable acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"}, Index: lib/plugins/acts_as_tree/test/acts_as_tree_test.rb =================================================================== --- lib/plugins/acts_as_tree/test/acts_as_tree_test.rb (revision 17354) +++ lib/plugins/acts_as_tree/test/acts_as_tree_test.rb (working copy) @@ -43,8 +43,8 @@ class Mixin < ActiveRecord::Base end -class TreeMixin < Mixin - acts_as_tree :foreign_key => "parent_id", :order => "id" +class TreeMixin < Mixin + acts_as_tree :foreign_key => "parent_id", :order => Arel.sql("id") end class TreeMixinWithoutOrder < Mixin @@ -57,7 +57,7 @@ end class TreeTest < Test::Unit::TestCase - + def setup setup_db @root1 = TreeMixin.create! @@ -146,12 +146,12 @@ assert_equal [@root_child1, @root_child2], @root_child2.self_and_siblings assert_equal [@root1, @root2, @root3], @root2.self_and_siblings assert_equal [@root1, @root2, @root3], @root3.self_and_siblings - end + end end class TreeTestWithEagerLoading < Test::Unit::TestCase - - def setup + + def setup teardown_db setup_db @root1 = TreeMixin.create! @@ -160,9 +160,9 @@ @root_child2 = TreeMixin.create! :parent_id => @root1.id @root2 = TreeMixin.create! @root3 = TreeMixin.create! - + @rc1 = RecursivelyCascadedTreeMixin.create! - @rc2 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc1.id + @rc2 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc1.id @rc3 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc2.id @rc4 = RecursivelyCascadedTreeMixin.create! :parent_id => @rc3.id end @@ -170,36 +170,36 @@ def teardown teardown_db end - + def test_eager_association_loading roots = TreeMixin.find(:all, :include => :children, :conditions => "mixins.parent_id IS NULL", :order => "mixins.id") - assert_equal [@root1, @root2, @root3], roots + assert_equal [@root1, @root2, @root3], roots assert_no_queries do assert_equal 2, roots[0].children.size assert_equal 0, roots[1].children.size assert_equal 0, roots[2].children.size - end + end end - + def test_eager_association_loading_with_recursive_cascading_three_levels_has_many root_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :children => { :children => :children } }, :order => 'mixins.id') assert_equal @rc4, assert_no_queries { root_node.children.first.children.first.children.first } end - + def test_eager_association_loading_with_recursive_cascading_three_levels_has_one root_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :first_child => { :first_child => :first_child } }, :order => 'mixins.id') assert_equal @rc4, assert_no_queries { root_node.first_child.first_child.first_child } end - + def test_eager_association_loading_with_recursive_cascading_three_levels_belongs_to leaf_node = RecursivelyCascadedTreeMixin.find(:first, :include => { :parent => { :parent => :parent } }, :order => 'mixins.id DESC') assert_equal @rc1, assert_no_queries { leaf_node.parent.parent.parent } - end + end end class TreeTestWithoutOrder < Test::Unit::TestCase - - def setup + + def setup setup_db @root1 = TreeMixinWithoutOrder.create! @root2 = TreeMixinWithoutOrder.create! @@ -212,8 +212,8 @@ def test_root assert [@root1, @root2].include?(TreeMixinWithoutOrder.root) end - + def test_roots assert_equal [], [@root1, @root2] - TreeMixinWithoutOrder.roots end -end +end Index: lib/redmine/helpers/gantt.rb =================================================================== --- lib/redmine/helpers/gantt.rb (revision 17354) +++ lib/redmine/helpers/gantt.rb (working copy) @@ -139,7 +139,7 @@ def issues @issues ||= @query.issues( :include => [:assigned_to, :tracker, :priority, :category, :fixed_version], - :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC", + :order => Arel.sql("#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC"), :limit => @max_rows ) end Index: lib/redmine/sort_criteria.rb =================================================================== --- lib/redmine/sort_criteria.rb (revision 17354) +++ lib/redmine/sort_criteria.rb (working copy) @@ -78,7 +78,7 @@ sql = self.collect do |k,o| if s = sortable_columns[k] s = [s] unless s.is_a?(Array) - s.collect {|c| append_order(c, o)} + s.collect {|c| Arel.sql(append_order(c, o))} end end.flatten.compact sql.blank? ? nil : sql Index: test/unit/query_test.rb =================================================================== --- test/unit/query_test.rb (revision 17354) +++ test/unit/query_test.rb (working copy) @@ -1483,7 +1483,7 @@ c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } assert c assert c.sortable - issues = q.issues(:order => "#{c.sortable} ASC") + issues = q.issues(:order => Arel.sql("#{c.sortable} ASC")) values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s} assert !values.empty? assert_equal values.sort, values @@ -1494,7 +1494,7 @@ c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } assert c assert c.sortable - issues = q.issues(:order => "#{c.sortable} DESC") + issues = q.issues(:order => Arel.sql("#{c.sortable} DESC")) values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s} assert !values.empty? assert_equal values.sort.reverse, values @@ -1505,7 +1505,7 @@ c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' } assert c assert c.sortable - issues = q.issues(:order => "#{c.sortable} ASC") + issues = q.issues(:order => Arel.sql("#{c.sortable} ASC")) values = issues.collect {|i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end}.compact assert !values.empty? assert_equal values.sort, values @@ -1703,7 +1703,7 @@ def test_issue_ids q = IssueQuery.new(:name => '_') - order = "issues.subject, issues.id" + order = Arel.sql("issues.subject, issues.id") issues = q.issues(:order => order) assert_equal issues.map(&:id), q.issue_ids(:order => order) end