Skip to content

Commit

Permalink
Remove NULLS FIRST/LAST. closes #5152
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Feb 25, 2012
1 parent 862e27f commit 404b73b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -1189,7 +1189,7 @@ def distinct(columns, orders) #:nodoc:


# Construct a clean list of column names from the ORDER BY clause, removing # Construct a clean list of column names from the ORDER BY clause, removing
# any ASC/DESC modifiers # 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.delete_if { |c| c.blank? }
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" } order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }


Expand Down
Expand Up @@ -185,6 +185,11 @@ def test_partial_index
assert_equal "(number > 100)", index.where assert_equal "(number > 100)", index.where
end 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 private
def insert(ctx, data) def insert(ctx, data)
binds = data.map { |name, value| binds = data.map { |name, value|
Expand Down

0 comments on commit 404b73b

Please sign in to comment.