title: Auto create related object in db using before_create
body: <p>In my application I have a Question model and a QuestionResult model. They are related through a Question has_one QuestionResult and I am trying to get Rails to auto create its related QuestionResult entry when I am creating the Question entry.</p>
  
  <p>Here is what I have tried in the Question model:</p>
  
  <pre><code>before_create :create_result_record_and_populate_difficulty
  
  has_one :question_result, :dependent =&gt; :destroy
  
  def create_result_record_and_populate_difficulty
    self.build_question_result(:current_difficulty =&gt; initial_difficulty)
  end
  </code></pre>
  
  <p>Initial difficulty is simply an attribute of the Question model which I am using to set the current difficulty in the associated QuestionResult model. I know the method is being called because I have placed an "raise" statement within the method and it triggers the exception when I run "rake db:seed" to add some questions.</p>
  
  <p>However, no QuestionResult entries are found in the db even if the db seeding is successful.</p>
  
  <p>Is there anything wrong with the way this should be done? Please help enlighten me :)</p>