Skip to content

Commit 53a9043

Browse files
miloopstenderlove
authored andcommitted
Refactor finder conditions look up and assigment for apply_finder_conditions.
1 parent 90c114d commit 53a9043

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

activerecord/lib/active_record/relation/spawn_methods.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,16 @@ def apply_finder_options(options)
9797
return relation unless options
9898

9999
options.assert_valid_keys(VALID_FIND_OPTIONS)
100+
finders = options.dup
101+
finders.delete_if { |key, value| value.nil? }
100102

101-
[:joins, :select, :group, :having, :limit, :offset, :from, :lock].each do |finder|
102-
if value = options[finder]
103-
relation = relation.send(finder, value)
104-
end
105-
end
106-
107-
relation = relation.readonly(options[:readonly]) if options.key? :readonly
108-
109-
[:group, :order].each do |finder|
110-
relation.send("#{finder}_values=", relation.send("#{finder}_values") + Array.wrap(options[finder])) if options.has_key?(finder)
103+
([:joins, :select, :group, :order, :having, :limit, :offset, :from, :lock, :readonly] & finders.keys).each do |finder|
104+
relation = relation.send(finder, finders[finder])
111105
end
112106

113-
relation = relation.where(options[:conditions]) if options.has_key?(:conditions)
114-
relation = relation.includes(options[:include]) if options.has_key?(:include)
115-
relation = relation.extending(options[:extend]) if options.has_key?(:extend)
107+
relation = relation.where(finders[:conditions]) if options.has_key?(:conditions)
108+
relation = relation.includes(finders[:include]) if options.has_key?(:include)
109+
relation = relation.extending(finders[:extend]) if options.has_key?(:extend)
116110

117111
relation
118112
end

0 commit comments

Comments
 (0)