mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simplify finder method definitions
This commit is contained in:
parent
fc4f237864
commit
a68a3e9af6
1 changed files with 11 additions and 13 deletions
|
@ -8,11 +8,10 @@ module ActiveRecord
|
||||||
|
|
||||||
class_eval <<-CEVAL
|
class_eval <<-CEVAL
|
||||||
def #{query_method}(*args)
|
def #{query_method}(*args)
|
||||||
spawn.tap do |new_relation|
|
new_relation = spawn
|
||||||
new_relation.#{query_method}_values ||= []
|
value = Array.wrap(args.flatten).reject {|x| x.blank? }
|
||||||
value = Array.wrap(args.flatten).reject {|x| x.blank? }
|
new_relation.#{query_method}_values += value if value.present?
|
||||||
new_relation.#{query_method}_values += value if value.present?
|
new_relation
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CEVAL
|
CEVAL
|
||||||
end
|
end
|
||||||
|
@ -20,11 +19,10 @@ module ActiveRecord
|
||||||
[:where, :having].each do |query_method|
|
[:where, :having].each do |query_method|
|
||||||
class_eval <<-CEVAL
|
class_eval <<-CEVAL
|
||||||
def #{query_method}(*args)
|
def #{query_method}(*args)
|
||||||
spawn.tap do |new_relation|
|
new_relation = spawn
|
||||||
new_relation.#{query_method}_values ||= []
|
value = build_where(*args)
|
||||||
value = build_where(*args)
|
new_relation.#{query_method}_values += [*value] if value.present?
|
||||||
new_relation.#{query_method}_values += [*value] if value.present?
|
new_relation
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CEVAL
|
CEVAL
|
||||||
end
|
end
|
||||||
|
@ -34,9 +32,9 @@ module ActiveRecord
|
||||||
|
|
||||||
class_eval <<-CEVAL
|
class_eval <<-CEVAL
|
||||||
def #{query_method}(value = true)
|
def #{query_method}(value = true)
|
||||||
spawn.tap do |new_relation|
|
new_relation = spawn
|
||||||
new_relation.#{query_method}_value = value
|
new_relation.#{query_method}_value = value
|
||||||
end
|
new_relation
|
||||||
end
|
end
|
||||||
CEVAL
|
CEVAL
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue