提交 d22ffa16 编写于 作者: R Ryuta Kamizono

Delegate to `Enumerable#find` for `CollectionProxy`

Since `Relation` includes `Enumerable`, it is enough to use `super`
simply.
上级 e3962308
......@@ -74,23 +74,19 @@ def reset
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)
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
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
scope.find(*args)
result
end
else
scope.find(*args)
end
end
......
......@@ -135,8 +135,9 @@ def loaded?
# # #<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
##
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册