aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2005-10-20 15:05:48 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2005-10-20 15:05:48 +0000
commit5f0b9369cc857ef007a9b0f573b63225e342e4fd (patch)
tree73f1ec0d8680d9ba38fe7095fe89a1e4225a3add
parent7219e82fe600ff1268b9a89efc7a289ac0108592 (diff)
downloadrails-5f0b9369cc857ef007a9b0f573b63225e342e4fd.tar.gz
rails-5f0b9369cc857ef007a9b0f573b63225e342e4fd.tar.bz2
rails-5f0b9369cc857ef007a9b0f573b63225e342e4fd.zip
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
-rw-r--r--activerecord/CHANGELOG4
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb2
-rwxr-xr-xactiverecord/test/associations_test.rb9
3 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index c1926a20c7..6478436bd0 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,6 +1,8 @@
*1.12.1* (October 19th, 2005)
-* HABTM finders shouldn't return readonly records. #2525 [patrick@lenz.sh]
+* Fixed Association#clear for associations which have not yet been accessed. #2524 [Patrick Lenz <patrick@lenz.sh>]
+
+* HABTM finders shouldn't return readonly records. #2525 [Patrick Lenz <patrick@lenz.sh>]
* Make all tests runnable on their own. #2521. [Blair Zajac <blair@orcaware.com>]
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index ced734cfcd..164d11b2d1 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -59,7 +59,7 @@ module ActiveRecord
# Removes all records from this association. Returns +self+ so method calls may be chained.
def clear
- return self if empty? # forces load_target if hasn't happened already
+ return self if length.zero? # forces load_target if hasn't happened already
if @options[:exclusively_dependent]
destroy_all
else
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 47562f9176..2d7ebc2b42 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -566,6 +566,15 @@ class HasManyAssociationsTest < Test::Unit::TestCase
assert Client.find_by_id(client_id).nil?
end
+ def test_clearing_without_initial_access
+ firm = companies(:first_firm)
+
+ firm.clients_of_firm.clear
+
+ assert_equal 0, firm.clients_of_firm.size
+ assert_equal 0, firm.clients_of_firm(true).size
+ end
+
def test_deleting_a_item_which_is_not_in_the_collection
force_signal37_to_load_all_clients_of_firm
summit = Client.find_first("name = 'Summit'")