提交 952737af 编写于 作者: F Francesco Rodriguez

add CollectionProxy#find documentation

上级 ba896d37
......@@ -36,6 +36,26 @@ module Associations
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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册