diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-19 14:58:19 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-19 14:58:19 -0500 |
commit | 952737af35be26ac4760efa3b06a0313ceae2c68 (patch) | |
tree | 145ff675bdead8bd865e557cf81680d112ad5a36 /activerecord/lib | |
parent | ba896d37e3b43ec19cf86b7a6452718d9077db20 (diff) | |
download | rails-952737af35be26ac4760efa3b06a0313ceae2c68.tar.gz rails-952737af35be26ac4760efa3b06a0313ceae2c68.tar.bz2 rails-952737af35be26ac4760efa3b06a0313ceae2c68.zip |
add CollectionProxy#find documentation
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index fa316a8c9d..1c22309d99 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -37,6 +37,26 @@ module ActiveRecord 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 |