Permalink
Browse files

Merge pull request #7232 from kennyj/fix_7200

Fix #7200. Backport #5168 to 3-2-stable
  • Loading branch information...
2 parents 5365c10 + f137c2b commit 59c4b22c4528e9f97d3eb394f603dc50c3cf41a9 @carlosantoniodasilva carlosantoniodasilva committed Aug 2, 2012
@@ -1108,7 +1108,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.gsub(/\s+(ASC|DESC)\s*/i, '') }
+ order_columns = orders.collect { |s| s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\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}" }
@@ -179,6 +179,11 @@ def test_substitute_at
assert_equal Arel.sql('$2'), bind
end
+ def test_distinct_with_nulls
+ assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls first"])
+ assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"])
+ end
+
private
def insert(ctx, data)
binds = data.map { |name, value|

0 comments on commit 59c4b22

Please sign in to comment.