diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index bfb02144b..3293d2084 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -321,6 +321,9 @@ class IssueQuery < Query unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)} order_option << "#{Issue.table_name}.id DESC" end + order_option = order_option. + collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first). + collect{|arr| Arel.sql(arr.join(' '))} scope = Issue.visible. joins(:status, :project). @@ -367,6 +370,9 @@ class IssueQuery < Query unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)} order_option << "#{Issue.table_name}.id DESC" end + order_option = order_option. + collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first). + collect{|arr| Arel.sql(arr.join(' '))} Issue.visible. joins(:status, :project). diff --git a/app/models/project_query.rb b/app/models/project_query.rb index 54c16d8e6..95ecdbd7d 100644 --- a/app/models/project_query.rb +++ b/app/models/project_query.rb @@ -92,8 +92,11 @@ class ProjectQuery < Query def results_scope(options={}) order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?) - order_option << "#{Project.table_name}.lft ASC" + order_option = order_option. + collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first). + collect{|arr| Arel.sql(arr.join(' '))} + scope = base_scope. order(order_option). joins(joins_for_order_statement(order_option.join(','))) diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index dd59d1067..a7dc69dac 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -151,8 +151,11 @@ class TimeEntryQuery < Query def results_scope(options={}) order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?) - order_option << "#{TimeEntry.table_name}.id ASC" + order_option = order_option. + collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first). + collect{|arr| Arel.sql(arr.join(' '))} + base_scope. order(order_option). joins(joins_for_order_statement(order_option.join(',')))