aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonak Jangir <ronakjangir47@gmail.com>2015-08-22 22:56:04 +0530
committerRonak Jangir <ronakjangir47@gmail.com>2015-08-23 07:28:27 +0530
commitf9f156b22c77eb01c009eaac421afcb2a2d6673f (patch)
treeb5fac72dd1de72779635d2a332dcd610b02a43d7
parentec760e67fd9be26de165c912dfd0dd0f3f31b4b8 (diff)
downloadrails-f9f156b22c77eb01c009eaac421afcb2a2d6673f.tar.gz
rails-f9f156b22c77eb01c009eaac421afcb2a2d6673f.tar.bz2
rails-f9f156b22c77eb01c009eaac421afcb2a2d6673f.zip
Added docs for CollectionProxy#take [ci skip]
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index b5a8c81fe4..29c711082a 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -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