Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix reverse order with new Arel Nodes (#1571)

  • Loading branch information...
commit 7c6a8406f41e77ec6c93f1385e34b5209eacabda 1 parent 0b794f9
@oriolgual oriolgual authored
View
2  activerecord/lib/active_record/relation/query_methods.rb
@@ -307,7 +307,7 @@ def reverse_sql_order(order_query)
order_query.map do |o|
case o
- when Arel::Nodes::Ordering
+ when Arel::Nodes::Ascending, Arel::Nodes::Descending
o.reverse
when String, Symbol
o.to_s.split(',').collect do |s|
View
12 activerecord/test/cases/relation_scoping_test.rb
@@ -15,6 +15,18 @@ def test_reverse_order
assert_equal Developer.order("id DESC").to_a.reverse, Developer.order("id DESC").reverse_order
end
+ def test_reverse_order_with_arel_node
+ assert_equal Developer.order("id DESC").to_a.reverse, Developer.order(Developer.arel_table[:id].desc).reverse_order
+ end
+
+ def test_reverse_order_with_multiple_arel_nodes
+ assert_equal Developer.order("id DESC").order("name DESC").to_a.reverse, Developer.order(Developer.arel_table[:id].desc).order(Developer.arel_table[:name].desc).reverse_order
+ end
+
+ def test_reverse_order_with_arel_nodes_and_strings
+ assert_equal Developer.order("id DESC").order("name DESC").to_a.reverse, Developer.order("id DESC").order(Developer.arel_table[:name].desc).reverse_order
+ end
+
def test_double_reverse_order_produces_original_order
assert_equal Developer.order("name DESC"), Developer.order("name DESC").reverse_order.reverse_order
end
Please sign in to comment.
Something went wrong with that request. Please try again.