Browse files

Merge pull request #10212 from mariovisic/active_record_doc

Add documentation for `collection.create!` on has_many records. [ci skip]
  • Loading branch information...
2 parents 130d3a0 + 3b2af1b commit c78da9aed9453bf2c933392e7ae7831f3d2ef73e @carlosantoniodasilva carlosantoniodasilva committed Apr 15, 2013
Showing with 4 additions and 0 deletions.
  1. +4 −0 activerecord/lib/active_record/associations.rb
View
4 activerecord/lib/active_record/associations.rb
@@ -1073,6 +1073,9 @@ module ClassMethods
# with +attributes+, linked to this object through a foreign key, and that has already
# been saved (if it passed the validation). *Note*: This only works if the base model
# already exists in the DB, not if it is a new (unsaved) record!
+ # [collection.create!(attributes = {})]
+ # Does the same as <tt>collection.create</tt>, but raises <tt>ActiveRecord::RecordInvalid</tt>
+ # if the record is invalid.
#
# (*Note*: +collection+ is replaced with the symbol passed as the first argument, so
# <tt>has_many :clients</tt> would add among others <tt>clients.empty?</tt>.)
@@ -1094,6 +1097,7 @@ module ClassMethods
# * <tt>Firm#clients.exists?(name: 'ACME')</tt> (similar to <tt>Client.exists?(name: 'ACME', firm_id: firm.id)</tt>)
# * <tt>Firm#clients.build</tt> (similar to <tt>Client.new("firm_id" => id)</tt>)
# * <tt>Firm#clients.create</tt> (similar to <tt>c = Client.new("firm_id" => id); c.save; c</tt>)
+ # * <tt>Firm#clients.create!</tt> (similar to <tt>c = Client.new("firm_id" => id); c.save!</tt>)
# The declaration can also include an options hash to specialize the behavior of the association.
#
# === Options

0 comments on commit c78da9a

Please sign in to comment.