mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #21332 from ronakjangir47/take_docs
Added docs for CollectionProxy#take
This commit is contained in:
commit
c106ba9f8d
1 changed files with 25 additions and 0 deletions
|
@ -227,6 +227,31 @@ module ActiveRecord
|
|||
@association.last(*args)
|
||||
end
|
||||
|
||||
# Gives a record (or N records if a parameter is supplied) from the collection
|
||||
# using the same rules as <tt>ActiveRecord::Base.take</tt>.
|
||||
#
|
||||
# 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.take # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
|
||||
#
|
||||
# person.pets.take(2)
|
||||
# # => [
|
||||
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
|
||||
# # #<Pet id: 2, name: "Spook", person_id: 1>
|
||||
# # ]
|
||||
#
|
||||
# another_person_without.pets # => []
|
||||
# another_person_without.pets.take # => nil
|
||||
# another_person_without.pets.take(2) # => []
|
||||
def take(n = nil)
|
||||
@association.take(n)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue