Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor finder conditions look up and assigment for apply_finder_con…

…ditions.
  • Loading branch information...
commit 993572472af63ca480093c612799e50dbcf78206 1 parent ab1ab5f
Emilio Tagua miloops authored tenderlove committed
Showing with 7 additions and 13 deletions.
  1. +7 −13 activerecord/lib/active_record/relation/spawn_methods.rb
20 activerecord/lib/active_record/relation/spawn_methods.rb
View
@@ -97,22 +97,16 @@ def apply_finder_options(options)
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
Please sign in to comment.
Something went wrong with that request. Please try again.