title: Factory Girl: How to set up a has_many/through association
body: <p>I've been struggling with setting up a <code>has_many/through</code> relationship using Factory Girl.</p>
  
  <p>I have the following models:</p>
  
  <pre><code>class Job &lt; ActiveRecord::Base
    has_many :job_details, :dependent =&gt; :destroy
    has_many :details, :through =&gt; :job_details
  end
  
  class Detail &lt; ActiveRecord::Base
    has_many :job_details, :dependent =&gt; :destroy
    has_many :jobs, :through =&gt; :job_details
  end
  
  class JobDetail &lt; ActiveRecord::Base
    attr_accessible :job_id, :detail_id
    belongs_to :job
    belongs_to :detail
  end
  </code></pre>
  
  <p>My Factory:</p>
  
  <pre><code>factory :job do
    association     :tenant
    title           { Faker::Company.catch_phrase }
    company         { Faker::Company.name }
    company_url     { Faker::Internet.domain_name }
    purchaser_email { Faker::Internet.email }
    description     { Faker::Lorem.paragraphs(3) }
    how_to_apply    { Faker::Lorem.sentence }
    location        "New York, NY"
  end
  
  factory :detail do
    association :detail_type &lt;--another Factory not show here
    description "Full Time"
  end
  
  factory :job_detail do
    association :job
    association :detail
  end
  </code></pre>
  
  <p>What I want is for my job factory to be created with a default <code>Detail</code> of "Full Time".</p>
  
  <p>I've been trying to follow this, but have not had any luck:
  <a href="https://stackoverflow.com/questions/8650204/factorygirl-has-many-through">FactoryGirl Has Many through</a></p>
  
  <p>I'm not sure how the <code>after_create</code> should be used to attach the Detail via JobDetail.</p>