title: FactoryGirls multiple associations
body: <p>I'm having the hardest time thinking through this. I'm very new to FactoryGirl, so this may be explained clearly somewhere and I apologize if that is the case. This is certainly not a unique problem, maybe my Google skills aren't quite up to par.</p>
  
  <p>I am working orders, which belong to category and belong to customer. I'm trying to build a customer who's placed 5 orders, however I keep throwing unique errors when it tries to build the category (which requires a unique name).</p>
  
  <h1>features/customer_spec.rb</h1>
  
  <pre><code>RSpec.feature "Customer management", :type =&gt; :feature do
      scenario "Customer with orders has order history" do
          customer = create(:customer, :with_5_completed_orders)
          visit customer_path(customer)
          expect(page).to have_content("Recent Orders")
      end
  end
  </code></pre>
  
  <h1>factories/customers.rb</h1>
  
  <pre><code>FactoryGirl.define do
  
      factory :customer do
  
          ...
  
          trait :with_5_completed_orders do
              after :create do |customer|
              create_list(:order_line, 5, :completed, :customer =&gt; customer)
          end
        end
     end
  end
  </code></pre>
  
  <h1>factories/order_line.rb</h1>
  
  <pre><code>FactoryGirl.define do
      factory :order_line do
          ....
          product
          ....
      end
  end
  </code></pre>
  
  <h1>factories/product.rb</h1>
  
  <pre><code>FactoryGirl.define do
  
      factory :product do |f|
          ....
          category
          ....
      end
  end
  </code></pre>
  
  <h1>factories/categories.rb</h1>
  
  <pre><code>FactoryGirl.define do
      sequence :category_name do |n|
        "category-#{n}"
      end
  
     factory :category do
         name { generate(:category_name) } 
     end
  end
  </code></pre>