diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-13 18:17:21 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-13 18:24:46 +0900 |
commit | d22ffa1625e28db1c1150d422c16686d71f69e6c (patch) | |
tree | ced5b0ba87df2d6b1212c72255bfbb6d4d7b481e /activerecord/lib/active_record/associations/collection_association.rb | |
parent | e3962308e7947f3d99c70c192e2d1356d3420e1e (diff) | |
download | rails-d22ffa1625e28db1c1150d422c16686d71f69e6c.tar.gz rails-d22ffa1625e28db1c1150d422c16686d71f69e6c.tar.bz2 rails-d22ffa1625e28db1c1150d422c16686d71f69e6c.zip |
Delegate to `Enumerable#find` for `CollectionProxy`
Since `Relation` includes `Enumerable`, it is enough to use `super`
simply.
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 26 |
1 files changed, 11 insertions, 15 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 |