Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v4.1.8) is shown here.
columns_for_distinct(columns, orders)
public
PostgreSQL requires the ORDER BY columns
in the select list for distinct queries, and requires that the ORDER BY
include the distinct column.
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 491
def columns_for_distinct(columns, orders) #:nodoc:
order_columns = orders.reject(&:blank?).map{ |s|
# Convert Arel node to string
s = s.to_sql unless s.is_a?(String)
# Remove any ASC/DESC modifiers
s.gsub(/\s+(?:ASC|DESC)\b/, '')
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/, '')
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
[super, *order_columns].join(', ')
end