public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix include? on has_many collections with finder_sql to fall back to Array 
include? rather than try to use SQL.
[#18 state:resolved]
joshuabates (author)
Thu Apr 17 11:58:32 -0700 2008
NZKoz (committer)
Wed Apr 23 01:18:09 -0700 2008
commit  b6aa0e13b4e590b82550a6464924f431e57229df
tree    48afd640a589e8d727ec52eda8daadc29a183356
parent  ae51013c3f7b8a8579fcb99d889ed80e9dd75797
...
214
215
216
 
217
218
219
...
214
215
216
217
218
219
220
0
@@ -214,6 +214,7 @@ module ActiveRecord
0
 
0
       def include?(record)
0
         return false unless record.is_a?(@reflection.klass)
0
+        load_target if @reflection.options[:finder_sql] && !loaded?
0
         return @target.include?(record) if loaded?
0
         exists?(record)
0
       end
...
832
833
834
 
 
 
 
 
 
 
 
 
 
 
835
836
837
...
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
0
@@ -832,6 +832,17 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
0
     assert ! firm.clients.loaded?
0
   end
0
 
0
+  def test_include_loads_collection_if_target_uses_finder_sql
0
+    firm = companies(:first_firm)
0
+    client = firm.clients_using_sql.first
0
+    
0
+    firm.reload
0
+    assert ! firm.clients_using_sql.loaded?
0
+    assert firm.clients_using_sql.include?(client)
0
+    assert firm.clients_using_sql.loaded?
0
+  end
0
+  
0
+
0
   def test_include_returns_false_for_non_matching_record_to_verify_scoping
0
     firm = companies(:first_firm)
0
     client = Client.create!(:name => 'Not Associated')

Comments