diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-04 16:34:42 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-05 16:22:18 +0000 |
commit | 9a111c7cf94d9e4614a0687345084cfe60a69187 (patch) | |
tree | 4e95259c2d4fb0eb5c63d13b8e10c57716426ab8 /activerecord | |
parent | 562583c7667f508493ab8c5b1a4215087fafd22d (diff) | |
download | rails-9a111c7cf94d9e4614a0687345084cfe60a69187.tar.gz rails-9a111c7cf94d9e4614a0687345084cfe60a69187.tar.bz2 rails-9a111c7cf94d9e4614a0687345084cfe60a69187.zip |
Use uniq instead of manually putting a DISTINCT in the query
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 6cc401e6cc..6f8b76abda 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -20,31 +20,19 @@ module ActiveRecord # It's okay to just apply all these like this. The options will only be present if the # association supports that option; this is enforced by the association builder. scope = scope.apply_finder_options(options.slice( - :readonly, :include, :order, :limit, :joins, :group, :having, :offset)) + :readonly, :include, :order, :limit, :joins, :group, :having, :offset, :select)) if options[:through] && !options[:include] scope = scope.includes(source_options[:include]) end - if select = select_value - scope = scope.select(select) - end + scope = scope.uniq if options[:uniq] add_constraints(scope) end private - def select_value - select_value = options[:select] - - if reflection.collection? - select_value ||= options[:uniq] && "DISTINCT #{reflection.quoted_table_name}.*" - end - - select_value - end - def add_constraints(scope) tables = construct_tables |