title: Factory_girl has_one relation with validates_presence_of
body: <p>I have 2 Models:</p>
  
  <pre><code># user.rb
  class User &lt; ActiveRecord::Base
    has_one :profile, :dependent =&gt; :destroy
  end
  
  # profile.rb
  class Profile &lt; ActiveRecord::Base
    belongs_to :user
    validates_presence_of :user
  end
  
  # user_factory.rb
  Factory.define :user do |u|
    u.login "test"
    u.association :profile
  end
  </code></pre>
  
  <p>I want to do this:</p>
  
  <pre><code>@user = Factory(:user)
  =&gt; #&lt;User id: 88,....&gt;
  @user.profile
  =&gt; #&lt;Profile id:123, user_id:88, ......&gt;
  
  @user = Factory.build(:user)
  =&gt; #&lt;User id: nil,....&gt;
  @user.profile
  =&gt; #&lt;Profile id:nil, user_id:nil, ......&gt;
  </code></pre>
  
  <p>But this doesn't work!
  It tells me that my profile model isn't correct because there is no user! (it saves the profile before the user, so there is no user_id...)</p>
  
  <p>How can I fix this? Tried everything.. :(
  And I need to call Factory.create(:user)...</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Fixed this issue - working now with:</p>
  
  <pre><code># user_factory.rb
  Factory.define :user do |u|
    u.profile { Factory.build(:profile)}
  end
  
  # user.rb
  class User &lt; ActiveRecord::Base
    has_one :profile, :dependent =&gt; :destroy, :inverse_of =&gt; :user
  end
  
  # profile.rb
  class Profile &lt; ActiveRecord::Base
    belongs_to :user
    validates_presence_of :user
  end
  </code></pre>