title: "Type Error: class or module required" for two-to-many relationship
body: <p>In my rails app, I have essentially an "account" and a "transaction" model.  The "transaction" model <code>belongs_to</code> the "account" model twice, once as a <code>credited_account</code> and once as a <code>debited_account</code>.  It looks something like this:</p>
  
  <pre><code>class Account &lt; ActiveRecord::Base
    has_many :credits, :class_name =&gt; "Transaction", :foreign_key =&gt; 'credited_account_id'
    has_many :debits, :class_name =&gt; "Transaction", :foreign_key =&gt; 'debited_account_id'
  # ... validators and such ... #
  end
  
  class Transaction &lt; ActiveRecord::Base
    belongs_to :credited_account, :class =&gt; "Account"
    belongs_to :debited_account, :class =&gt; "Account"
  end
  </code></pre>
  
  <p>This all works, but I am running into some issues with my specs.</p>
  
  <p>Using RSpec and Factory_Girl, I get a TypeError every time I run a spec which calls for the transaction factory.  Rspec output as follows:</p>
  
  <pre><code>Failure/Error: transaction = build(:transaction)
   TypeError:
     class or module required
  </code></pre>
  
  <p>below is my spec/factories.rb</p>
  
  <pre><code>  FactoryGirl.define do
    factory :account do
       #... account factory ...#
    end
  
    factory :transaction do
      association :credited_account, factory: :account
      #... other attributes set here ...#
      association :debited_account, factory: :account
    end
  end
  </code></pre>
  
  <p>Any insight is greatly appreciated!</p>
  
  <p>Regards</p>