aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-19 00:37:47 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-19 00:37:47 -0500
commitbb887b92f8ed119641d68487cef1b5b34b2518a1 (patch)
tree155492abb7370cd949da0d7ea61c7ddd28a0582b /activerecord/lib
parent3f46f73d004eb19616ad9863fefa4c21ef1d76c3 (diff)
downloadrails-bb887b92f8ed119641d68487cef1b5b34b2518a1.tar.gz
rails-bb887b92f8ed119641d68487cef1b5b34b2518a1.tar.bz2
rails-bb887b92f8ed119641d68487cef1b5b34b2518a1.zip
add CollectionProxy#<< documentation
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb20
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 50f9aecd56..54e497fdca 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -238,6 +238,26 @@ module ActiveRecord
end
alias_method :to_a, :to_ary
+ # Adds one or more +records+ to the collection by setting their foreign keys
+ # to the collection‘s primary key. Returns +self+, so several appends may be
+ # chained together.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets.size # => 0
+ # person.pets << Pet.new(name: 'Fancy-Fancy')
+ # person.pets << [Pet.new(name: 'Spook'), Pet.new(name: 'Choo-Choo')]
+ # person.pets.size # => 3
+ #
+ # person.id # => 1
+ # 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>
+ # # ]
def <<(*records)
proxy_association.concat(records) && self
end