diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-04-18 22:24:03 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-04-18 22:24:03 +0000 |
commit | 5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e (patch) | |
tree | 018fb3d33183214d9ff93168ae8babcf2d422759 /activerecord | |
parent | b170fd771ca6ed6818a1983e136d9f6aca1f3531 (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 6afeefd581..5aba184c82 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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.] 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 |