mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Associations#select_limited_ids_list adds the ORDER BY columns to the SELECT DISTINCT List for postgresql. [Rick]
|
||||
|
||||
* DRY up association collection reader method generation. [Marcel Molina Jr.]
|
||||
|
||||
* DRY up and tweak style of the validation error object. [Marcel Molina Jr.]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user