Skip to content

Commit

Permalink
update CollectionProxy#delete_all documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed May 22, 2012
1 parent f9a718e commit 1bcd5e4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions activerecord/lib/active_record/associations/collection_proxy.rb
Expand Up @@ -228,7 +228,8 @@ class CollectionProxy < Relation
# #
# If no <tt>:dependent</tt> option is given, then it will follow the # If no <tt>:dependent</tt> option is given, then it will follow the
# default strategy. The default strategy is <tt>:nullify</tt>. This # default strategy. The default strategy is <tt>:nullify</tt>. This
# sets the foreign keys to <tt>NULL</tt>. # sets the foreign keys to <tt>NULL</tt>. For, +has_many+ <tt>:through</tt>,
# the default strategy is +delete_all+.
# #
# class Person < ActiveRecord::Base # class Person < ActiveRecord::Base
# has_many :pets # dependent: :nullify option by default # has_many :pets # dependent: :nullify option by default
Expand Down Expand Up @@ -260,7 +261,8 @@ class CollectionProxy < Relation
# # ] # # ]
# #
# If it is set to <tt>:destroy</tt> all the objects from the collection # If it is set to <tt>:destroy</tt> 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 # class Person < ActiveRecord::Base
# has_many :pets, dependent: :destroy # has_many :pets, dependent: :destroy
Expand All @@ -283,6 +285,31 @@ class CollectionProxy < Relation
# #
# Pet.find(1, 2, 3) # Pet.find(1, 2, 3)
# # => ActiveRecord::RecordNotFound # # => ActiveRecord::RecordNotFound
#
# If it is set to <tt>:delete_all</tt>, 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
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
#
# person.pets.delete_all
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
#
# Pet.find(1, 2, 3)
# # => ActiveRecord::RecordNotFound


## ##
# :method: destroy_all # :method: destroy_all
Expand Down

0 comments on commit 1bcd5e4

Please sign in to comment.