32737_exclude_same_column_from_orderby.patch

Yuichi HARADA, 2020-01-22 09:40

Download (2.41 KB)

View differences:

app/models/issue_query.rb
321 321
    unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)}
322 322
      order_option << "#{Issue.table_name}.id DESC"
323 323
    end
324
    order_option = order_option.
325
      collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first).
326
      collect{|arr| Arel.sql(arr.join(' '))}
324 327

  
325 328
    scope = Issue.visible.
326 329
      joins(:status, :project).
......
367 370
    unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)}
368 371
      order_option << "#{Issue.table_name}.id DESC"
369 372
    end
373
    order_option = order_option.
374
      collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first).
375
      collect{|arr| Arel.sql(arr.join(' '))}
370 376

  
371 377
    Issue.visible.
372 378
      joins(:status, :project).
app/models/project_query.rb
92 92

  
93 93
  def results_scope(options={})
94 94
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
95

  
96 95
    order_option << "#{Project.table_name}.lft ASC"
96
    order_option = order_option.
97
      collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first).
98
      collect{|arr| Arel.sql(arr.join(' '))}
99

  
97 100
    scope = base_scope.
98 101
      order(order_option).
99 102
      joins(joins_for_order_statement(order_option.join(',')))
app/models/time_entry_query.rb
151 151

  
152 152
  def results_scope(options={})
153 153
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
154

  
155 154
    order_option << "#{TimeEntry.table_name}.id ASC"
155
    order_option = order_option.
156
      collect{|s| s.split(/\s+(ASC|DESC)\s*,?\s*/i)}.flatten.each_slice(2).uniq(&:first).
157
      collect{|arr| Arel.sql(arr.join(' '))}
158

  
156 159
    base_scope.
157 160
      order(order_option).
158 161
      joins(joins_for_order_statement(order_option.join(',')))