diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2013-03-19 14:00:04 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2013-03-19 14:00:04 -0700 |
commit | 0fe4ae93b4f902ac5757304e015c415bf986a0d0 (patch) | |
tree | 31b0d6db4f658e1bf92d944544c7e8ec189ce46e /activerecord/lib | |
parent | 67a2c731c322c290d7ed44726a33d50489d1ed95 (diff) | |
parent | 840ca09a1151fafe1cb3299f12437378d25f2ce5 (diff) | |
download | rails-0fe4ae93b4f902ac5757304e015c415bf986a0d0.tar.gz rails-0fe4ae93b4f902ac5757304e015c415bf986a0d0.tar.bz2 rails-0fe4ae93b4f902ac5757304e015c415bf986a0d0.zip |
Merge pull request #9529 from wangjohn/find_on_inverse_of_bugfix_9470
Find() on an association with an inverse will now scan existing in-memory records
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 906560bd44..73b4a187c8 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -79,7 +79,7 @@ module ActiveRecord if block_given? load_target.find(*args) { |*block_args| yield(*block_args) } else - if options[:finder_sql] + if options[:finder_sql] || options[:inverse_of] find_by_scan(*args) else scope.find(*args) @@ -567,7 +567,8 @@ module ActiveRecord end end - # If using a custom finder_sql, #find scans the entire collection. + # If using a custom finder_sql or if the :inverse_of option has been + # specified, then #find scans the entire collection. def find_by_scan(*args) expects_array = args.first.kind_of?(Array) ids = args.flatten.compact.map{ |arg| arg.to_i }.uniq |