Skip to content

Commit

Permalink
improve CollectionProxy#destroy documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed May 21, 2012
1 parent d831734 commit 1f5c1a1
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions activerecord/lib/active_record/associations/collection_proxy.rb
Expand Up @@ -248,7 +248,7 @@ class CollectionProxy < Relation
# :method: destroy # :method: destroy
# Destroy the +records+ supplied and remove them from the collection. # Destroy the +records+ supplied and remove them from the collection.
# This method will _always_ remove record from the database ignoring # This method will _always_ remove record from the database ignoring
# the +:dependent+ option. Returns an array with the deleted records. # the +:dependent+ option. Returns an array with the removed records.
# #
# class Person < ActiveRecord::Base # class Person < ActiveRecord::Base
# has_many :pets # has_many :pets
Expand Down Expand Up @@ -278,10 +278,42 @@ class CollectionProxy < Relation
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1> # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ] # # ]
# #
# person.pets.size # => 0 # person.pets.size # => 0
# person.pets # => [] # person.pets # => []
# #
# Pet.find([1, 2, 3]) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (1, 2, 3) # Pet.find(1, 2, 3) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (1, 2, 3)
#
# You can pass +Fixnum+ or +String+ values, it finds the records
# responding to the +id+ and then deletes them from the database.
#
# person.pets.size # => 3
# person.pets
# # => [
# # #<Pet id: 4, name: "Benny", person_id: 1>,
# # #<Pet id: 5, name: "Brain", person_id: 1>,
# # #<Pet id: 6, name: "Boss", person_id: 1>
# # ]
#
# person.pets.destroy("4")
# # => #<Pet id: 4, name: "Benny", person_id: 1>
#
# person.pets.size # => 2
# person.pets
# # => [
# # #<Pet id: 5, name: "Brain", person_id: 1>,
# # #<Pet id: 6, name: "Boss", person_id: 1>
# # ]
#
# person.pets.destroy(5, 6)
# # => [
# # #<Pet id: 5, name: "Brain", person_id: 1>,
# # #<Pet id: 6, name: "Boss", person_id: 1>
# # ]
#
# person.pets.size # => 0
# person.pets # => []
#
# Pet.find(4, 5, 6) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (4, 5, 6)


## ##
# :method: empty? # :method: empty?
Expand All @@ -298,7 +330,7 @@ class CollectionProxy < Relation
# #
# person.pets.count # => 0 # person.pets.count # => 0
# person.pets.empty? # => true # person.pets.empty? # => true

## ##
# :method: any? # :method: any?
# Returns true if the collection is not empty. # Returns true if the collection is not empty.
Expand Down

0 comments on commit 1f5c1a1

Please sign in to comment.