title: Rails: Validating association after save?
body: <p>I have a <code>User</code> model which has many <code>roles</code>. Roles contains a <code>user_id</code> field, which I want to <code>validate_presence_of</code></p>
  
  <p>The issue is: if I assign a role to user upon create, the validation fails because no user_id is set. Now, I <em>do</em> want to validate that a user_id exists, but I need to save the user before checking that.</p>
  
  <p>The code currently looks like this:</p>
  
  <pre><code>@user = User.new(params[:user])
  @user.roles &lt;&lt; Role.new(:name =&gt; 'Peon') unless @user.has_roles?
  if @user.save
    # ...
  </code></pre>
  
  <p>The only ways I can think of getting around the problem involves either disabling the validation, which I don't want to do, or double-saving to the DB, which isn't exactly efficient.</p>
  
  <p>What's the standard way for handling this issue?</p>