From fd67e3befc748e91b4ad0b09be7f3cca69bb7380 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 25 Jan 2005 10:04:49 +0000 Subject: The create and build methods are only available for has_one/belongs_to if an association already exist. It will not work when it's nil. Updated the documentation to reflect that. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@501 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index afd1a0cb45..b9cae482aa 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -35,7 +35,6 @@ module ActiveRecord # The project class now has the following methods (and more) to ease the traversal and manipulation of its relationships: # * Project#portfolio, Project#portfolio=(portfolio), Project#portfolio.nil? # * Project#project_manager, Project#project_manager=(project_manager), Project#project_manager.nil?, - # Project#project_manager.build, Project#project_manager.create # * Project#milestones.empty?, Project#milestones.size, Project#milestones, Project#milestones<<(milestone), # Project#milestones.delete(milestone), Project#milestones.find(milestone_id), Project#milestones.find_all(conditions), # Project#milestones.build, Project#milestones.create @@ -249,9 +248,11 @@ module ActiveRecord # and saves the associate object. # * association.nil? - returns true if there is no associated object. # * association.build(attributes = {}) - returns a new object of the associated type that has been instantiated - # with +attributes+ and linked to this object through a foreign key but has not yet been saved. + # with +attributes+ and linked to this object through a foreign key but has not yet been saved. Note: This ONLY works if + # an association already exists. It will NOT work if the association is nil. # * association.create(attributes = {}) - returns a new object of the associated type that has been instantiated # with +attributes+ and linked to this object through a foreign key and that has already been saved (if it passed the validation). + # Note: This ONLY works if an association already exists. It will NOT work if the association is nil. # # Example: An Account class declares has_one :beneficiary, which will add: # * Account#beneficiary (similar to Beneficiary.find_first "account_id = #{id}") -- cgit v1.2.3