4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/composite_primary_keys/relation/query_methods.rb', line 4
def reverse_sql_order(order_query)
if order_query.empty?
if primary_key
return primary_key.map do |key|
table[key].desc
end
else
raise IrreversibleOrderError,
"Relation has no current order and table has no primary key to be used as default order"
end
end
order_query.flat_map do |o|
case o
when Arel::Attribute
o.desc
when Arel::Nodes::Ordering
o.reverse
when String
if does_not_support_reverse?(o)
raise IrreversibleOrderError, "Order #{o.inspect} can not be reversed automatically"
end
o.split(",").map! do |s|
s.strip!
s.gsub!(/\sasc\Z/i, " DESC") || s.gsub!(/\sdesc\Z/i, " ASC") || (s << " DESC")
end
else
o
end
end
end
|