diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-09 17:35:00 -0300 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-09 13:45:49 -0700 |
commit | 53a90436cff23380f64c9c4fbad74d4e240b60c2 (patch) | |
tree | a1f179d2372ff9706e2bb886580c0732c86d4701 | |
parent | 90c114de67483109f0c6871b2266dd1ad2582b7a (diff) | |
download | rails-53a90436cff23380f64c9c4fbad74d4e240b60c2.tar.gz rails-53a90436cff23380f64c9c4fbad74d4e240b60c2.tar.bz2 rails-53a90436cff23380f64c9c4fbad74d4e240b60c2.zip |
Refactor finder conditions look up and assigment for apply_finder_conditions.
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index ba8efb5409..f039645255 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -97,22 +97,16 @@ module ActiveRecord return relation unless options options.assert_valid_keys(VALID_FIND_OPTIONS) + finders = options.dup + finders.delete_if { |key, value| value.nil? } - [:joins, :select, :group, :having, :limit, :offset, :from, :lock].each do |finder| - if value = options[finder] - relation = relation.send(finder, value) - end - end - - relation = relation.readonly(options[:readonly]) if options.key? :readonly - - [:group, :order].each do |finder| - relation.send("#{finder}_values=", relation.send("#{finder}_values") + Array.wrap(options[finder])) if options.has_key?(finder) + ([:joins, :select, :group, :order, :having, :limit, :offset, :from, :lock, :readonly] & finders.keys).each do |finder| + relation = relation.send(finder, finders[finder]) end - relation = relation.where(options[:conditions]) if options.has_key?(:conditions) - relation = relation.includes(options[:include]) if options.has_key?(:include) - relation = relation.extending(options[:extend]) if options.has_key?(:extend) + relation = relation.where(finders[:conditions]) if options.has_key?(:conditions) + relation = relation.includes(finders[:include]) if options.has_key?(:include) + relation = relation.extending(finders[:extend]) if options.has_key?(:extend) relation end |