Skip to content

Commit

Permalink
avoid multiple hash lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Aug 11, 2010
1 parent 5352a89 commit ff760dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions activerecord/lib/active_record/relation/spawn_methods.rb
Expand Up @@ -80,10 +80,14 @@ def apply_finder_options(options)

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)
Expand Down

0 comments on commit ff760dd

Please sign in to comment.