提交 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 ...@@ -74,23 +74,19 @@ def reset
end end
def find(*args) def find(*args)
if block_given? if options[:inverse_of] && loaded?
load_target.find(*args) { |*block_args| yield(*block_args) } args_flatten = args.flatten
else raise RecordNotFound, "Couldn't find #{scope.klass.name} without an ID" if args_flatten.blank?
if options[:inverse_of] && loaded? result = find_by_scan(*args)
args_flatten = args.flatten
raise RecordNotFound, "Couldn't find #{scope.klass.name} without an ID" if args_flatten.blank? result_size = Array(result).size
result = find_by_scan(*args) if !result || result_size != args_flatten.size
scope.raise_record_not_found_exception!(args_flatten, result_size, args_flatten.size)
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
else else
scope.find(*args) result
end end
else
scope.find(*args)
end end
end end
......
...@@ -135,8 +135,9 @@ def loaded? ...@@ -135,8 +135,9 @@ def loaded?
# # #<Pet id: 2, name: "Spook", person_id: 1>, # # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1> # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ] # # ]
def find(*args, &block) def find(*args)
@association.find(*args, &block) return super if block_given?
@association.find(*args)
end end
## ##
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册