Browse files

applying to stable: Associations#select_limited_ids_list adds the ORD…

…ER BY columns to the SELECT DISTINCT List for postgresql. [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@4233 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8118c48 commit 982d187691a894f6432ed258d5334c6e4f799c36 @technoweenie technoweenie committed Apr 19, 2006
Showing with 10 additions and 4 deletions.
  1. +5 −0 activerecord/CHANGELOG
  2. +5 −4 activerecord/lib/active_record/associations.rb
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Associations#select_limited_ids_list adds the ORDER BY columns to the SELECT DISTINCT List for postgresql. [Rick]
+
+
*1.14.2* (April 9th, 2005)
* Fixed calculations for the Oracle Adapter (closes #4626) [Michael Schoen]
View
9 activerecord/lib/active_record/associations.rb
@@ -1163,18 +1163,19 @@ def add_limited_ids_condition!(sql, options, join_dependency)
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

0 comments on commit 982d187

Please sign in to comment.