diff options
| author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-22 11:02:43 -0500 | 
|---|---|---|
| committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-22 11:03:07 -0500 | 
| commit | 2c62dd64dbaf1b3c758e7259fa8fefbafbbdcf81 (patch) | |
| tree | 940bd906558575a4bb17a00e4dd479858a259c64 | |
| parent | 63f094bf2984127132589f5c93e6dabcad898b12 (diff) | |
| download | rails-2c62dd64dbaf1b3c758e7259fa8fefbafbbdcf81.tar.gz rails-2c62dd64dbaf1b3c758e7259fa8fefbafbbdcf81.tar.bz2 rails-2c62dd64dbaf1b3c758e7259fa8fefbafbbdcf81.zip | |
add CollectionProxy#build documentation
| -rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 9ee69157b3..6c8fcec0c4 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -168,6 +168,37 @@ module ActiveRecord        #   another_person_without.pets.last(3) # => []        ## +      # :method: build +      # +      # :call-seq: +      #   build(attributes = {}, options = {}, &block) +      # +      # Returns a new object of the collection type that has been instantiated +      # with +attributes+ and linked to this object, but have not yet been saved. +      # You can pass an array of attributes hashes, this will return an array +      # with the new objects. +      # +      #   class Person +      #     has_many :pets +      #   end +      # +      #   person.pets.build +      #   # => #<Pet id: nil, name: nil, person_id: 1> +      # +      #   person.pets.build(name: 'Fancy-Fancy') +      #   # => #<Pet id: nil, name: "Fancy-Fancy", person_id: 1> +      # +      #   person.pets.build([{name: 'Spook'}, {name: 'Choo-Choo'}, {name: 'Brain'}]) +      #   # => [ +      #   #      #<Pet id: nil, name: "Spook", person_id: 1>, +      #   #      #<Pet id: nil, name: "Choo-Choo", person_id: 1>, +      #   #      #<Pet id: nil, name: "Brain", person_id: 1> +      #   #    ] +      # +      #   person.pets.size  # => 5 # size of the collection +      #   person.pets.count # => 0 # count from database + +      ##        # :method: concat        # Add one or more records to the collection by setting their foreign keys        # to the association's primary key. Since << flattens its argument list and | 
