diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2011-07-05 10:51:40 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2011-07-05 10:51:40 +0300 |
commit | 8ba0c1ac5315c24cd7132267152b9d126c6ddf52 (patch) | |
tree | 3ee888c06afafd43968f3ff1f6f45b8236e434b8 /activerecord/lib/active_record | |
parent | 9f7442a3abf1242a2348bfdd0c700f707ee04c52 (diff) | |
download | rails-8ba0c1ac5315c24cd7132267152b9d126c6ddf52.tar.gz rails-8ba0c1ac5315c24cd7132267152b9d126c6ddf52.tar.bz2 rails-8ba0c1ac5315c24cd7132267152b9d126c6ddf52.zip |
Fixed CollectionAssociation#find to be compatible with Array#find
In order to make CollectionAssociation behave closer to Array
Add the ability to pass block to #find method just like Array#find does.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 224e0095d9..c15ee18e53 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -78,10 +78,14 @@ module ActiveRecord end def find(*args) - if options[:finder_sql] - find_by_scan(*args) + if block_given? + load_target.find(*args) { |*block_args| yield(*block_args) } else - scoped.find(*args) + if options[:finder_sql] + find_by_scan(*args) + else + scoped.find(*args) + end end end |