From 3ef693724c4719564361b3f48f8977b795c935e0 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 16 Jan 2011 18:37:09 +0000 Subject: Document the new create_association! method on one-to-one associations --- activerecord/lib/active_record/associations.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 70c8e75e20..4760a5fa57 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -208,7 +208,7 @@ module ActiveRecord # other=(other) | X | X | X # build_other(attributes={}) | X | | X # create_other(attributes={}) | X | | X - # other.create!(attributes={}) | | | X + # create_other!(attributes={}) | X | | X # # ===Collection associations (one-to-many / many-to-many) # | | | has_many @@ -1042,6 +1042,9 @@ module ActiveRecord # Returns a new object of the associated type that has been instantiated # with +attributes+, linked to this object through a foreign key, and that # has already been saved (if it passed the validation). + # [create_association!(attributes = {})] + # Does the same as create_association, but raises ActiveRecord::RecordInvalid + # if the record is invalid. # # (+association+ is replaced with the symbol passed as the first argument, so # has_one :manager would add among others manager.nil?.) @@ -1053,6 +1056,7 @@ module ActiveRecord # * Account#beneficiary=(beneficiary) (similar to beneficiary.account_id = account.id; beneficiary.save) # * Account#build_beneficiary (similar to Beneficiary.new("account_id" => id)) # * Account#create_beneficiary (similar to b = Beneficiary.new("account_id" => id); b.save; b) + # * Account#create_beneficiary! (similar to b = Beneficiary.new("account_id" => id); b.save!; b) # # === Options # @@ -1157,6 +1161,9 @@ module ActiveRecord # Returns a new object of the associated type that has been instantiated # with +attributes+, linked to this object through a foreign key, and that # has already been saved (if it passed the validation). + # [create_association!(attributes = {})] + # Does the same as create_association, but raises ActiveRecord::RecordInvalid + # if the record is invalid. # # (+association+ is replaced with the symbol passed as the first argument, so # belongs_to :author would add among others author.nil?.) @@ -1168,6 +1175,7 @@ module ActiveRecord # * Post#author=(author) (similar to post.author_id = author.id) # * Post#build_author (similar to post.author = Author.new) # * Post#create_author (similar to post.author = Author.new; post.author.save; post.author) + # * Post#create_author! (similar to post.author = Author.new; post.author.save!; post.author) # The declaration can also include an options hash to specialize the behavior of the association. # # === Options -- cgit v1.2.3