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
|
||||
def #{query_method}(*args)
|
||||
spawn.tap do |new_relation|
|
||||
new_relation.#{query_method}_values ||= []
|
||||
new_relation = spawn
|
||||
value = Array.wrap(args.flatten).reject {|x| x.blank? }
|
||||
new_relation.#{query_method}_values += value if value.present?
|
||||
end
|
||||
new_relation
|
||||
end
|
||||
CEVAL
|
||||
end
|
||||
|
@ -20,11 +19,10 @@ module ActiveRecord
|
|||
[:where, :having].each do |query_method|
|
||||
class_eval <<-CEVAL
|
||||
def #{query_method}(*args)
|
||||
spawn.tap do |new_relation|
|
||||
new_relation.#{query_method}_values ||= []
|
||||
new_relation = spawn
|
||||
value = build_where(*args)
|
||||
new_relation.#{query_method}_values += [*value] if value.present?
|
||||
end
|
||||
new_relation
|
||||
end
|
||||
CEVAL
|
||||
end
|
||||
|
@ -34,9 +32,9 @@ module ActiveRecord
|
|||
|
||||
class_eval <<-CEVAL
|
||||
def #{query_method}(value = true)
|
||||
spawn.tap do |new_relation|
|
||||
new_relation = spawn
|
||||
new_relation.#{query_method}_value = value
|
||||
end
|
||||
new_relation
|
||||
end
|
||||
CEVAL
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue