From 10d375efaa85cbfab11def8ddff7069b18da7064 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 18 May 2012 00:22:32 -0500 Subject: add examples to CollectionAssociation#concat --- .../associations/collection_association.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index b00483a421..bfc2058a2c 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -124,8 +124,19 @@ module ActiveRecord create_record(attributes, options, true, &block) end - # Add +records+ to this association. Returns +self+ so method calls may be chained. - # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically. + # Add +records+ to this association. Returns +self+ so method calls may + # be chained. Since << flattens its argument list and inserts each record, + # +push+ and +concat+ behave identically. + # + # class Person < ActiveRecord::Base + # pets :has_many + # end + # + # person.pets << Person.new(name: 'Nemo') + # person.pets.concat(Person.new(name: 'Droopy')) + # person.pets.push(Person.new(name: 'Ren')) + # + # person.pets # => [#, #, #] def concat(*records) load_target if owner.new_record? @@ -151,7 +162,7 @@ module ActiveRecord end end - # Remove all records from this association + # Remove all records from this association. # # See delete for more info. def delete_all -- cgit v1.2.3