Permalink
Browse files

Reject blank order_values within #columns_for_distinct, as the orders…

… aren't used at all on non-postgres adapters.
  • Loading branch information...
1 parent 32a5cad commit ec75ff34517c98d8feb6ad81ae79c44e611b92e7 @Empact Empact committed May 10, 2013
@@ -470,7 +470,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
# PostgreSQL requires the ORDER BY columns in the select list for distinct queries, and
# requires that the ORDER BY include the distinct column.
def columns_for_distinct(columns, orders) #:nodoc:
- order_columns = orders.map{ |s|
+ 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
@@ -244,8 +244,8 @@ def apply_join_dependency(relation, join_dependency)
end
def construct_limited_ids_condition(relation)
- orders = relation.order_values.map { |val| val.presence }.compact
- values = @klass.connection.columns_for_distinct("#{quoted_table_name}.#{quoted_primary_key}", orders)
+ values = @klass.connection.columns_for_distinct(
+ "#{quoted_table_name}.#{quoted_primary_key}", relation.order_values)
relation = relation.dup.select(values).distinct!

0 comments on commit ec75ff3

Please sign in to comment.