1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Delegate to Enumerable#find for CollectionProxy

Since `Relation` includes `Enumerable`, it is enough to use `super`
simply.
This commit is contained in:
Ryuta Kamizono 2017-08-13 18:17:21 +09:00
parent e3962308e7
commit d22ffa1625
2 changed files with 13 additions and 16 deletions

View file

@ -74,23 +74,19 @@ module ActiveRecord
end
def find(*args)
if block_given?
load_target.find(*args) { |*block_args| yield(*block_args) }
else
if options[:inverse_of] && loaded?
args_flatten = args.flatten
raise RecordNotFound, "Couldn't find #{scope.klass.name} without an ID" if args_flatten.blank?
result = find_by_scan(*args)
if options[:inverse_of] && loaded?
args_flatten = args.flatten
raise RecordNotFound, "Couldn't find #{scope.klass.name} without an ID" if args_flatten.blank?
result = find_by_scan(*args)
result_size = Array(result).size
if !result || result_size != args_flatten.size
scope.raise_record_not_found_exception!(args_flatten, result_size, args_flatten.size)
else
result
end
result_size = Array(result).size
if !result || result_size != args_flatten.size
scope.raise_record_not_found_exception!(args_flatten, result_size, args_flatten.size)
else
scope.find(*args)
result
end
else
scope.find(*args)
end
end

View file

@ -135,8 +135,9 @@ module ActiveRecord
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
def find(*args, &block)
@association.find(*args, &block)
def find(*args)
return super if block_given?
@association.find(*args)
end
##