Forum: Ruby on Rails Question regarding has_one and association_build

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6e96154e5c4f7b759d1c1c064ba4da42?d=identicon&s=25 Eric L. (Guest)
on 2009-05-05 18:48
(Received via mailing list)
In the doc, there's is a note saying association_build "only works if
an association already exists. It will NOT work if the association is
nil."  But in my test, it works fine when the association is nil.  For
example,

class Post < ActiveRecord::Base
  has_one :author

  def after_initialize
      build_author
  end
end

This works perfectly for me.  So is the warning in the doc something I
should be worried about?

Link to doc:
http://api.rubyonrails.org/classes/ActiveRecord/As...

Thanks,
Eric
This topic is locked and can not be replied to.