title: Factory Girl has_one through relationship?
body: <p>I am having great difficulty setting up Factory Girl to mimic my model associations. I believe the problem is that I am not setting up the &quot;User has one plan through subscription&quot; association up correctly. Any help is greatly appreciated!</p>
  <p>I am getting this error:</p>
  <pre><code> Failure/Error: let(:plan) {FactoryGirl.create(:plan, :user =&gt; user) }
   NoMethodError:
     undefined method `user=' for #&lt;Plan:0x007fd836a1a340&gt;
  </code></pre>
  <p>My models are as follows:</p>
  <h3>User.rb</h3>
  <pre><code>has_one :subscription
  has_one :plan, :through =&gt; :subscription
  has_many :projects
  </code></pre>
  <h3>Project.rb</h3>
  <pre><code>belongs_to :user
  </code></pre>
  <h3>Plan.rb</h3>
  <pre><code>has_many :subscriptions
  </code></pre>
  <h3>Subscription.rb</h3>
  <pre><code>belongs_to :plan
  belongs_to :user
  </code></pre>
  <p>And my FactoryGirl code</p>
  <pre><code>FactoryGirl.define do
  
    factory :user do
  
      first_name &quot;Joel&quot;
      last_name &quot;Brewer&quot;
      email { &quot;#{first_name}.#{last_name}@example.com&quot;.downcase }
      password &quot;booyabooya&quot;
      password_confirmation &quot;booyabooya&quot;
      user_type &quot;entrepreneur&quot;
    end
  
    factory :plan do |f|
      f.association :user
      f.plan_type &quot;entrepreneur&quot;
      f.plan_level &quot;bronze&quot;
      f.user_project_limit '1'
   end
  
    factory :subscription do |f|
      f.association :user
      f.association :plan
      f.stripe_card_token &quot;Test card token&quot;
      f.stripe_customer_token &quot;Test customer token&quot;
      f.email &quot;joel.brewer1@example.com&quot;
    end
  
    factory :project do
      title &quot;Sample Project&quot;
      user
    end
  end
  </code></pre>