Skip to content

Commit

Permalink
applying to stable: Associations#select_limited_ids_list adds the ORD…
Browse files Browse the repository at this point in the history
…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
technoweenie committed Apr 19, 2006
1 parent 8118c48 commit 982d187
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
9 changes: 5 additions & 4 deletions activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 982d187

Please sign in to comment.