Vote #81030
未完了Sorting of multiple columns including Date column does not work
0%
説明
When specifying the sorting condition of multiple columns including Date column in the custom query, sorting of columns after Date column does not work.
Defining a custom query
!{width:400px;border:1px solid #ccc;}customquery.png!List of spent time with custom query
!{width:400px;border:1px solid #ccc;}spenttime-with-customquery.png!
journals
I think the following patch will fix the problem.
<pre><code class="diff">
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index c8f8eeaeb..59a4f25ca 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -23,7 +23,7 @@ class TimeEntryQuery < Query
self.available_columns = [
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
- QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true),
+ QueryColumn.new(:spent_on, :sortable => "#{TimeEntry.table_name}.spent_on", :default_order => 'desc', :groupable => true),
TimestampQueryColumn.new(:created_on, :sortable => "#{TimeEntry.table_name}.created_on", :default_order => 'desc', :groupable => true),
QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => :label_week),
QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement}),
@@ -152,7 +152,12 @@ 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 <<
+ if order_option.reverse.find{|order| order.match?(/#{TimeEntry.table_name}\./)}&.match?(/\sDESC$/i)
+ "#{TimeEntry.table_name}.id DESC"
+ else
+ "#{TimeEntry.table_name}.id ASC"
+ end
base_scope.
order(order_option).
joins(joins_for_order_statement(order_option.join(',')))
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------