Skip to content

Commit

Permalink
Fix #594.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Feb 16, 2023
1 parent d54ca9e commit 8be6a9e
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/composite_primary_keys/relation/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ def reverse_sql_order(order_query)
end

order_query.flat_map do |o|
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
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
Expand Down

0 comments on commit 8be6a9e

Please sign in to comment.