aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-04-15 05:45:28 -0700
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-04-15 05:45:28 -0700
commitc78da9aed9453bf2c933392e7ae7831f3d2ef73e (patch)
treed842c1130ab5222a1c656b3cb665420efe7cf5d8 /activerecord
parent130d3a06ade83aec27cf1d2ff841dce9e0ad4dfd (diff)
parent3b2af1b8ce0cff8de786fec200730afb439d9dcd (diff)
downloadrails-c78da9aed9453bf2c933392e7ae7831f3d2ef73e.tar.gz
rails-c78da9aed9453bf2c933392e7ae7831f3d2ef73e.tar.bz2
rails-c78da9aed9453bf2c933392e7ae7831f3d2ef73e.zip
Merge pull request #10212 from mariovisic/active_record_doc
Add documentation for `collection.create!` on has_many records. [ci skip]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 3c92e379f1..5e5995f566 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1073,6 +1073,9 @@ module ActiveRecord
# 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 ActiveRecord
# * <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