title: Rails: How to make has_many :through association work with Single Table Inheritance
body: <p>So in my current project I have an Article model that can have different kinds of Transactions. It has one main Transaction, but under certain circumstances it can have multiple sub-transactions. </p>
  
  <p>Until now I set it up like this:</p>
  
  <pre><code>class Article &lt; ActiveRecord::Base
    has_one :transaction, inverse_of: :article
    has_many :partial_transactions, through: :transaction, source_type: 'MultipleFixedPriceTransaction', source: 'PartialFixedPriceTransaction', inverse_of: :articles
  end
  
  class Transaction &lt; ActiveRecord::Base
    belongs_to :article, inverse_of: :transaction # Gets inherited to all kinds of Transaction subclasses
  end
  
  class MultipleFixedPriceTransaction &lt; Transaction
    has_many :children, class_name: 'PartialFixedPriceTransaction', foreign_key: 'parent_id', inverse_of: :parent
  end
  
  class PartialFixedPriceTransaction &lt; Transaction
    belongs_to :parent, class_name: 'MultipleFixedPriceTransaction', inverse_of: :children
    belongs_to :article, inverse_of: :partial_transactions # Overwriting inheritance
  end
  </code></pre>
  
  <p>Now with this set up I sometimes get errors like</p>
  
  <pre><code>ActiveRecord::Reflection::ThroughReflection#foreign_key delegated to
  source_reflection.foreign_key, but source_reflection is nil:
  
  #&lt;ActiveRecord::Reflection::ThroughReflection:0x00000009bcc3f8 @macro=:has_many,
  @name=:partial_transactions, @options={:through=&gt;:transaction,
  :source_type=&gt;"MultipleFixedPriceTransaction",
  :source=&gt;"PartialFixedPriceTransaction", :inverse_of=&gt;:articles, :extend=&gt;[]},
  @active_record=Article(id: integer ...
  </code></pre>
  
  <p>By the way, I experimented a lot with the source and source_type parameters and the ones there are just examples. I don't really know what to do with them.</p>
  
  <p>So, how can I make this work? How is the association set up correctly?</p>
  
  <p>Thank you.</p>