aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-21 22:47:13 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-21 22:47:13 -0500
commit724a7866774c7847cc79b699ccf7da9fee72b154 (patch)
tree34c6bdb856b6c4b1734b7208910ee2cd21cb67ac /activerecord/lib
parent84f1b83df84d36b75cc7b6d1c84ffd84c6c07260 (diff)
downloadrails-724a7866774c7847cc79b699ccf7da9fee72b154.tar.gz
rails-724a7866774c7847cc79b699ccf7da9fee72b154.tar.bz2
rails-724a7866774c7847cc79b699ccf7da9fee72b154.zip
stop using distinct on for the unique id queries. [#6450 state:resolved]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index acc3e9c5e3..66ca831d6c 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -935,7 +935,7 @@ module ActiveRecord
# Return a DISTINCT ON() clause that's distinct on the columns we want but includes
# all the required columns for the ORDER BY to work properly.
- sql = "DISTINCT ON (#{columns}) #{columns}, "
+ sql = "DISTINCT #{columns}, "
sql << order_columns * ', '
end
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index aae257a0e7..a3d4b7f45a 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -246,6 +246,8 @@ module ActiveRecord
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