Permalink
Browse files

stop using distinct on for the unique id queries. [#6450 state:resolved]

  • Loading branch information...
1 parent 84f1b83 commit 724a7866774c7847cc79b699ccf7da9fee72b154 @tenderlove tenderlove committed Apr 22, 2011
@@ -935,7 +935,7 @@ def distinct(columns, orders) #:nodoc:
# Return a DISTINCT ON() clause that's distinct on the columns we want but includes
OhaiBBQ
OhaiBBQ Apr 22, 2011

You might want to change this comment

# all the required columns for the ORDER BY to work properly.
- sql = "DISTINCT ON (#{columns}) #{columns}, "
+ sql = "DISTINCT #{columns}, "
sql << order_columns * ', '
end
@@ -246,6 +246,8 @@ def construct_limited_ids_condition(relation)
orders = relation.order_values
values = @klass.connection.distinct("#{@klass.connection.quote_table_name table_name}.#{primary_key}", orders)
+ relation = relation.dup
+
ids_array = relation.select(values).collect {|row| row[primary_key]}
ids_array.empty? ? raise(ThrowResult) : table[primary_key].in(ids_array)
end

0 comments on commit 724a786

Please sign in to comment.