Skip to content
This repository
Browse code

Fix Associations#clear for not-yet-loaded associations (Patrick Lenz)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2695 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 5f0b9369cc857ef007a9b0f573b63225e342e4fd 1 parent 7219e82
authored October 20, 2005
4  activerecord/CHANGELOG
... ...
@@ -1,6 +1,8 @@
1 1
 *1.12.1* (October 19th, 2005)
2 2
 
3  
-* HABTM finders shouldn't return readonly records.  #2525 [patrick@lenz.sh]
  3
+* Fixed Association#clear for associations which have not yet been accessed. #2524 [Patrick Lenz <patrick@lenz.sh>]
  4
+
  5
+* HABTM finders shouldn't return readonly records.  #2525 [Patrick Lenz <patrick@lenz.sh>]
4 6
 
5 7
 * Make all tests runnable on their own. #2521. [Blair Zajac <blair@orcaware.com>]
6 8
 
2  activerecord/lib/active_record/associations/association_collection.rb
@@ -59,7 +59,7 @@ def delete(*records)
59 59
 
60 60
       # Removes all records from this association.  Returns +self+ so method calls may be chained.
61 61
       def clear
62  
-        return self if empty? # forces load_target if hasn't happened already
  62
+        return self if length.zero? # forces load_target if hasn't happened already
63 63
         if @options[:exclusively_dependent]
64 64
           destroy_all
65 65
         else          
9  activerecord/test/associations_test.rb
@@ -566,6 +566,15 @@ def test_clearing_an_exclusively_dependent_association_collection
566 566
     assert Client.find_by_id(client_id).nil?
567 567
   end                                                    
568 568
 
  569
+  def test_clearing_without_initial_access
  570
+    firm = companies(:first_firm)
  571
+
  572
+    firm.clients_of_firm.clear
  573
+
  574
+    assert_equal 0, firm.clients_of_firm.size
  575
+    assert_equal 0, firm.clients_of_firm(true).size
  576
+  end
  577
+
569 578
   def test_deleting_a_item_which_is_not_in_the_collection
570 579
     force_signal37_to_load_all_clients_of_firm
571 580
     summit = Client.find_first("name = 'Summit'")

0 notes on commit 5f0b936

Please sign in to comment.
Something went wrong with that request. Please try again.