From 1bcd5e42ed6c2efed4d1a53e74b4f8d6631b119d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Mon, 21 May 2012 23:49:41 -0500 Subject: update CollectionProxy#delete_all documentation --- .../active_record/associations/collection_proxy.rb | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 650d68a64a..f0c4688ee3 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -228,7 +228,8 @@ module ActiveRecord # # 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. + # sets the foreign keys to NULL. For, +has_many+ :through, + # the default strategy is +delete_all+. # # class Person < ActiveRecord::Base # has_many :pets # dependent: :nullify option by default @@ -260,7 +261,8 @@ module ActiveRecord # # ] # # If it is set to :destroy all the objects from the collection - # are destroyed by calling their +destroy+ method. + # are removed by calling their +destroy+ method. See +destroy+ for more + # information. # # class Person < ActiveRecord::Base # has_many :pets, dependent: :destroy @@ -283,6 +285,31 @@ module ActiveRecord # # Pet.find(1, 2, 3) # # => ActiveRecord::RecordNotFound + # + # If it is set to :delete_all, all the objects are deleted + # *without* calling their +destroy+ method. + # + # class Person < ActiveRecord::Base + # has_many :pets, dependent: :delete_all + # 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