title: Validation failed: [Object] code has already been taken
body: <p>I newbie in FactoryGirl.</p>
  
  <p>I have a lot of FactoryGirl models. They are related each other.</p>
  
  <p>I declared the following models as below: </p>
  
  <pre><code>class Organization &lt; ActiveRecord::Base
    has_many :org_plan_years
    has_many :subscribers
  end
  
  class Subscriber &lt; ActiveRecord::Base
    belongs_to :organization
  end
  
  class OrgPlanYear &lt; ActiveRecord::Base
    belongs_to :organization
    has_many :coverages
  end
  
  class Coverage &lt; ActiveRecord::Base
    belongs_to :subscriber
    belongs_to :org_plan_year
    belongs_to :organization
  end
  </code></pre>
  
  <p>And define FactoryGirl:  </p>
  
  <p><strong>factories/organizations.rb</strong></p>
  
  <pre><code>FactoryGirl.define do
    factory :organization_benefit, class Organization do
      name 'Benefit'
      organization_code '2341'
    end
  end
  </code></pre>
  
  <p><strong>factories/subscribers.rb</strong></p>
  
  <pre><code>FactoryGirl.define do
    factory :subscriber_875450002, class: Subscriber do
      association :organization, factory: :organization_benefit
      ssn 875450002
    end
  end
  </code></pre>
  
  <p><strong>factories/org_plan_years.rb</strong></p>
  
  <pre><code>FactoryGirl.define do
    factory :org_plan_year_benefit, class: OrgPlanYear do
      association :organization, factory: :organization_benefit
      name 'First OPY'
    end
  end
  </code></pre>
  
  <p><strong>factories/coverages.rb</strong></p>
  
  <pre><code>FactoryGirl.define do
    factory :coverage_1, class: Coverage do
      association :subscriber,    factory: :subscriber_875450002
      association :org_plan_year, factory: :org_plan_year_benefit
    end
  end
  </code></pre>
  
  <p>Sample of a test:</p>
  
  <pre><code>it 'test' do
    FactoryGirl.create(:coverage_1)
  end
  </code></pre>
  
  <p>When I run my test, I get an error like this:</p>
  
  <pre><code>ActiveRecord::RecordInvalid: Validation failed: Organization code has already been taken
  </code></pre>
  
  <p>I think, the problem is caused because I set up organization several times in factories, but I can't solve the problem.</p>