From 5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Tue, 18 Apr 2006 22:24:03 +0000 Subject: Associations#select_limited_ids_list adds the ORDER BY columns to the SELECT DISTINCT List for postgresql. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0099a461e1..88a2ad43ba 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1168,18 +1168,19 @@ module ActiveRecord end def select_limited_ids_list(options, join_dependency) - connection.select_values( + connection.select_all( construct_finder_sql_for_association_limiting(options, join_dependency), "#{name} Load IDs For Limited Eager Loading" - ).collect { |id| connection.quote(id) }.join(", ") + ).collect { |row| connection.quote(row[primary_key]) }.join(", ") end def construct_finder_sql_for_association_limiting(options, join_dependency) scope = scope(:find) - #sql = "SELECT DISTINCT #{table_name}.#{primary_key} FROM #{table_name} " sql = "SELECT " sql << "DISTINCT #{table_name}." if include_eager_conditions?(options) || include_eager_order?(options) - sql << "#{primary_key} FROM #{table_name} " + sql << primary_key + sql << ", #{options[:order].split(',').collect { |s| s.split.first } * ', '}" if options[:order] && (include_eager_conditions?(options) || include_eager_order?(options)) + sql << " FROM #{table_name} " if include_eager_conditions?(options) || include_eager_order?(options) sql << join_dependency.join_associations.collect{|join| join.association_join }.join -- cgit v1.2.3