提交 5ea76fab 编写于 作者: R Rick Olson

Associations#select_limited_ids_list adds the ORDER BY columns to the SELECT...

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
上级 b170fd77
*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 @@ 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册