Permalink
Browse files

add CollectionProxy#find documentation

  • Loading branch information...
1 parent ba896d3 commit 952737af35be26ac4760efa3b06a0313ceae2c68 Francesco Rodriguez committed May 19, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -37,6 +37,26 @@ class CollectionProxy < Relation
delegate :target, :load_target, :loaded?, :to => :@association
##
+ # :method: find
+ # Finds an object in the collection responding to the +id+. Uses the same
+ # rules as +ActiveRecord::Base.find+. Returns +ActiveRecord::RecordNotFound++
+ # error if the object can not be found.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # 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.find(1) # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
+ # person.pets.find(4) # => ActiveRecord::RecordNotFound: Couldn't find Pet with id=4
+
+ ##
# :method: first
# Returns the first record, or the first +n+ records, from the collection.
# If the collection is empty, the first form returns nil, and the second

0 comments on commit 952737a

Please sign in to comment.