diff options
author | Matthew Draper <matthew@trebex.net> | 2017-08-13 20:14:34 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-13 20:14:34 +0930 |
commit | 3e676822c05f1166e2880f162c864c3655eaa281 (patch) | |
tree | ced5b0ba87df2d6b1212c72255bfbb6d4d7b481e | |
parent | e3962308e7947f3d99c70c192e2d1356d3420e1e (diff) | |
parent | d22ffa1625e28db1c1150d422c16686d71f69e6c (diff) | |
download | rails-3e676822c05f1166e2880f162c864c3655eaa281.tar.gz rails-3e676822c05f1166e2880f162c864c3655eaa281.tar.bz2 rails-3e676822c05f1166e2880f162c864c3655eaa281.zip |
Merge pull request #30226 from kamipo/delegate_to_enumerable_find
Delegate to `Enumerable#find` for `CollectionProxy`
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 26 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 5 |
2 files changed, 14 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 1a424896fe..38e7ba39d3 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -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) - - 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 diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 0678b07699..412e89255d 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -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 ## |