title: FactoryGirl Self-referencing association error
body: <p>I'm trying to create a has_many:has_many relationship with factory girl.</p>
  
  <p>Here are my models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_many :user_roles
      has_many :roles, through: :user_roles
  end
  
  class UserRole &lt; ActiveRecord::Base
      belongs_to :user
      belongs_to :role
  end
  
  class Role &lt; ActiveRecord::Base
      has_many :user_roles
      has_many :users, through: :user_roles
  end
  </code></pre>
  
  <p>Here's the factory for my user:</p>
  
  <pre><code>FactoryGirl.define do
      factory :user do
          user_name { Faker::Name.user_name }
  
          trait :admin do
              association :user, factory: :admin, strategy: :create
          end
      end
  end
  </code></pre>
  
  <p>Here's the factory for an admin role:</p>
  
  <pre><code>FactoryGirl.define do
      factory :admin, class: Role do
          name 'admin'
      end
  end
  </code></pre>
  
  <p>The crux of this question is:</p>
  
  <pre><code>trait :admin do
      association :user, factory: :admin, strategy: :create
  end
  </code></pre>
  
  <p>I trigger it like this:</p>
  
  <blockquote>
    <p>FactoryGirl.create :user, :admin</p>
  </blockquote>
  
  <p>But that gives me:</p>
  
  <pre><code>FactoryGirl::AssociationDefinitionError: Self-referencing association 'user' in 'admin'
  </code></pre>
  
  <p>Why is this? And <strong>how should I make this user an admin? Should I create a <code>user_role</code> factory and create that?</strong></p>