Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for complex ordering of multiple columns on postgresql #1848

Merged
merged 1 commit into from

2 participants

@raviolicode
@raviolicode raviolicode Improve ordering of multiple columns on postgresql
* Only on postgresql, order("first asc, second asc") was invalid
* Closes #1720
9734a41
@spastorino spastorino merged commit d6413f0 into from
@jake3030 jake3030 referenced this pull request from a commit in jake3030/rails
Donald Parish Fixed http digest authentication to use credentials URI passed from c…
…lient. [#1848 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
86d8f92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 24, 2011
  1. @raviolicode

    Improve ordering of multiple columns on postgresql

    raviolicode authored
    * Only on postgresql, order("first asc, second asc") was invalid
    * Closes #1720
This page is out of date. Refresh to see the latest.
View
2  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -940,7 +940,7 @@ def distinct(columns, orders) #:nodoc:
# Construct a clean list of column names from the ORDER BY clause, removing
# any ASC/DESC modifiers
- order_columns = orders.collect { |s| s =~ /^(.+)\s+(ASC|DESC)\s*$/i ? $1 : s }
+ order_columns = orders.collect { |s| s.gsub(/\s+(ASC|DESC)\s*/i, '') }
order_columns.delete_if { |c| c.blank? }
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
View
7 activerecord/test/cases/relations_test.rb
@@ -176,6 +176,13 @@ def test_finding_with_order_and_take
assert_equal entrants(:first).name, entrants.first.name
end
+ def test_finding_with_cross_table_order_and_limit
+ tags = Tag.includes(:taggings) \
+ .order("tags.name asc, taggings.taggable_id asc, REPLACE('abc', taggings.taggable_type, taggings.taggable_type)") \
+ .limit(1).to_a
+ assert_equal 1, tags.length
+ end
+
def test_finding_with_complex_order_and_limit
tags = Tag.includes(:taggings).order("REPLACE('abc', taggings.taggable_type, taggings.taggable_type)").limit(1).to_a
assert_equal 1, tags.length
Something went wrong with that request. Please try again.