aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-18 22:24:03 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-18 22:24:03 +0000
commit5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e (patch)
tree018fb3d33183214d9ff93168ae8babcf2d422759 /activerecord/lib
parentb170fd771ca6ed6818a1983e136d9f6aca1f3531 (diff)
downloadrails-5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e.tar.gz
rails-5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e.tar.bz2
rails-5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e.zip
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
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb9
1 files changed, 5 insertions, 4 deletions
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