From f9a718eb5e3fe969c3a01cf084c6686cc2ce7aff Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Mon, 21 May 2012 23:30:13 -0500 Subject: add CollectionProxy#delete_all documentation --- .../active_record/associations/collection_proxy.rb | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index b419b9a749..650d68a64a 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -218,6 +218,71 @@ module ActiveRecord # # person.pets.replace(["doo", "ggie", "gaga"]) # # => ActiveRecord::AssociationTypeMismatch: Pet expected, got String + + + ## + # :method: delete_all + # Deletes all the records from the collection. For +has_many+ it will do the + # deletion according to the strategy specified by the :dependent + # option. Returns an array with the deleted records. + # + # If no :dependent option is given, then it will follow the + # default strategy. The default strategy is :nullify. This + # sets the foreign keys to NULL. + # + # class Person < ActiveRecord::Base + # has_many :pets # dependent: :nullify option by default + # end + # + # person.pets.size # => 3 + # person.pets + # # => [ + # # #, + # # #, + # # # + # # ] + # + # person.pets.delete_all + # # => [ + # # #, + # # #, + # # # + # # ] + # + # person.pets.size # => 0 + # person.pets # => [] + # + # Pet.find(1, 2, 3) + # # => [ + # # #, + # # #, + # # # + # # ] + # + # If it is set to :destroy all the objects from the collection + # are destroyed by calling their +destroy+ method. + # + # class Person < ActiveRecord::Base + # has_many :pets, dependent: :destroy + # end + # + # person.pets.size # => 3 + # person.pets + # # => [ + # # #, + # # #, + # # # + # # ] + # + # person.pets.delete_all + # # => [ + # # #, + # # #, + # # # + # # ] + # + # Pet.find(1, 2, 3) + # # => ActiveRecord::RecordNotFound ## # :method: destroy_all -- cgit v1.2.3