title: has_many and belongs_to associations in factory_girl
body: <p>I have these models that I'm trying to create factories for using factory_girl.</p>
  
  <pre><code>class Foo &lt; ActiveRecord::Base
    belongs_to :baz
  end
  
  class Baz &lt; ActiveRecord::Base
    has_many :foos
  end
  </code></pre>
  
  <p>I'm not sure how to create the factories without creating a loop where the factories endlessly call each other.</p>
  
  <pre><code>Factory.define :foo do |f|
    f.after_create do |ff|
      ff.baz = Factory(:baz)
    end
  end
  
  Factory.define :baz do |f|
    f.after_create do |ff|
      ff.foos = [Factory.create(:foo)]
    end
  end
  </code></pre>
  
  <p>I realize I can just leave out <code>ff.foos = [Factory.create(:foo)]</code> in the <code>baz</code> factory, but then in my <code>baz</code> tests I'm forced to used <code>foo.baz</code> instead of just using <code>baz</code>. Am I forced to use the <code>baz</code> object by fetching it out of a <code>foo</code> factory in my tests? Or is there a better way?</p>