diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-06 18:04:32 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-07 15:03:15 -0800 |
commit | 770e6893b9f2aaaebe3de10576931dc7194451bc (patch) | |
tree | a69337db0ed7743d302a9d54c142efa5447ab810 /activerecord/lib/active_record/associations/association_collection.rb | |
parent | 441118458d57011ee1b1f1dcfea558de462c6da9 (diff) | |
download | rails-770e6893b9f2aaaebe3de10576931dc7194451bc.tar.gz rails-770e6893b9f2aaaebe3de10576931dc7194451bc.tar.bz2 rails-770e6893b9f2aaaebe3de10576931dc7194451bc.zip |
Construct an actual ActiveRecord::Relation object for the association scope, rather than a hash which is passed to apply_finder_options. This allows more flexibility in how the scope is created, for example because scope.where(a, b) and scope.where(a).where(b) mean different things.
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index bd27365b08..f33a9ce732 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -333,23 +333,16 @@ module ActiveRecord protected - def finder_options - { - :conditions => construct_conditions, - :select => construct_select, - :readonly => @reflection.options[:readonly], - :order => @reflection.options[:order], - :limit => @reflection.options[:limit], - :include => @reflection.options[:include], - :joins => @reflection.options[:joins], - :group => @reflection.options[:group], - :having => @reflection.options[:having], - :offset => @reflection.options[:offset] - } - end - - def construct_select - @reflection.options[:select] || + def association_scope + options = @reflection.options.slice(:order, :limit, :joins, :group, :having, :offset) + super.apply_finder_options(options) + end + + def select_value + super || uniq_select_value + end + + def uniq_select_value @reflection.options[:uniq] && "DISTINCT #{@reflection.quoted_table_name}.*" end |