diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-10-13 08:29:00 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-10-13 08:29:00 +0000 |
commit | e789b26e652d9f0ee6ca538615b8d570cb4c91b5 (patch) | |
tree | d9c53e9f1668ecf144ebe23d8388c58d6549c8a5 /activerecord/lib/active_record/associations.rb | |
parent | ce1d14430f3ff5c8743541ce5f10b71a083f9c90 (diff) | |
download | rails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.tar.gz rails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.tar.bz2 rails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.zip |
fix select_limited_ids_list issues in postgresql, retain current behavior in other adapters [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5291 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index e075ecaf3c..d52695d162 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1192,13 +1192,18 @@ module ActiveRecord end def construct_finder_sql_for_association_limiting(options, join_dependency) - scope = scope(:find) + scope = scope(:find) + is_distinct = include_eager_conditions?(options) || include_eager_order?(options) sql = "SELECT " - sql << "DISTINCT #{table_name}." if include_eager_conditions?(options) || include_eager_order?(options) - sql << primary_key + if is_distinct + ordered_columns = options[:order].to_s.split(',').collect! { |s| s.split.first } + sql << connection.distinct("#{table_name}.#{primary_key}", ordered_columns) + else + sql << primary_key + end sql << " FROM #{table_name} " - if include_eager_conditions?(options) || include_eager_order?(options) + if is_distinct sql << join_dependency.join_associations.collect(&:association_join).join add_joins!(sql, options, scope) end |