Permalink
Browse files

add examples to CollectionAssociation#concat

  • Loading branch information...
1 parent 3ef1f94 commit 10d375efaa85cbfab11def8ddff7069b18da7064 Francesco Rodriguez committed May 18, 2012
Showing with 14 additions and 3 deletions.
  1. +14 −3 activerecord/lib/active_record/associations/collection_association.rb
@@ -124,8 +124,19 @@ def create!(attributes = {}, options = {}, &block)
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 # => [#<Pet name: "Nemo">, #<Pet name: "Droopy">, #<Pet name: "Ren">]
def concat(*records)
load_target if owner.new_record?
@@ -151,7 +162,7 @@ def transaction(*args)
end
end
- # Remove all records from this association
+ # Remove all records from this association.
#
# See delete for more info.
def delete_all

0 comments on commit 10d375e

Please sign in to comment.