Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate to Enumerable#find for CollectionProxy #30226

Merged
merged 1 commit into from
Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down