diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-11 14:59:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-11 15:00:08 -0700 |
commit | 06dc88445463513b58ed47ae8b21f853efda6898 (patch) | |
tree | 7bcdd777f163b5f78005fb7ba38264327a3412c5 /activerecord/lib | |
parent | ce529b4759cec26578b1fabf8de883f31f32ef90 (diff) | |
download | rails-06dc88445463513b58ed47ae8b21f853efda6898.tar.gz rails-06dc88445463513b58ed47ae8b21f853efda6898.tar.bz2 rails-06dc88445463513b58ed47ae8b21f853efda6898.zip |
avoid multiple hash lookups
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 7712ad2569..02db8d2b89 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -80,10 +80,14 @@ module ActiveRecord options.assert_valid_keys(VALID_FIND_OPTIONS) - [:joins, :select, :group, :having, :limit, :offset, :from, :lock, :readonly].each do |finder| - relation = relation.send(finder, options[finder]) if options.has_key?(finder) + [: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 + # Give precedence to newly-applied orders and groups to play nicely with with_scope [:group, :order].each do |finder| relation.send("#{finder}_values=", Array.wrap(options[finder]) + relation.send("#{finder}_values")) if options.has_key?(finder) |