Skip to content

Commit

Permalink
Reject blank order_values within #columns_for_distinct, as the orders…
Browse files Browse the repository at this point in the history
… aren't used at all on non-postgres adapters.
  • Loading branch information
Empact committed May 10, 2013
1 parent 32a5cad commit ec75ff3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/relation/finder_methods.rb
Expand Up @@ -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!

Expand Down

0 comments on commit ec75ff3

Please sign in to comment.