aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-17 23:30:51 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-17 23:30:51 -0500
commitfcc13f46f5f8db2a7010c00bd209d442461e948d (patch)
treefa149ac691f61c3a257cd572f547fc6b26e24fb5 /activerecord/lib/active_record/associations/collection_association.rb
parentc0c0ef59921a4a8795cd20348afc243cccc4821e (diff)
downloadrails-fcc13f46f5f8db2a7010c00bd209d442461e948d.tar.gz
rails-fcc13f46f5f8db2a7010c00bd209d442461e948d.tar.bz2
rails-fcc13f46f5f8db2a7010c00bd209d442461e948d.zip
add example to CollectionAssociation#destroy_all
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 11608a8ec1..7c31c8b923 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -4,7 +4,7 @@ module ActiveRecord
#
# CollectionAssociation is an abstract class that provides common stuff to
# ease the implementation of association proxies that represent
- # collections. See the class hierarchy in AssociationProxy
+ # collections. See the class hierarchy in AssociationProxy.
#
# CollectionAssociation:
# HasAndBelongsToManyAssociation => has_and_belongs_to_many
@@ -12,7 +12,7 @@ module ActiveRecord
# HasManyThroughAssociation + ThroughAssociation => has_many :through
#
# CollectionAssociation class provides common methods to the collections
- # defined by +has_and_belongs_to_many+, +has_many+ and +has_many+ with
+ # defined by +has_and_belongs_to_many+, +has_many+ or +has_many+ with
# +:through+ association option.
#
# You need to be careful with assumptions regarding the target: The proxy
@@ -170,6 +170,17 @@ module ActiveRecord
# Destroy all the records from this association.
#
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets.size # => 3
+ #
+ # person.pets.destroy_all
+ #
+ # person.pets.size # => 0
+ # person.pets # => []
+ #
# See destroy for more info.
def destroy_all
destroy(load_target).tap do
@@ -178,7 +189,7 @@ module ActiveRecord
end
end
- # Calculate sum using SQL, not Enumerable
+ # Calculate sum using SQL, not Enumerable.
def sum(*args)
if block_given?
scoped.sum(*args) { |*block_args| yield(*block_args) }