title: Rails preloading polymorphic association
body: <p>I have the following model relations:</p>
  
  <pre><code>class Customer &lt; ActiveRecord::Base
     has_many transactions
  end
  class Transaction &lt; ActiveRecord::Base
     belongs_to :customer
     belongs_to :ta_type, polymorphic: true
  end 
  
  class Downpament &lt; ActiveRecord::Base
     has_one :transaction, as: :ta_type
  end 
   class Installemnt &lt; ActiveRecord::Base
     has_one :transaction, as: :ta_type
  end 
  </code></pre>
  
  <p>I am able to preload the polymorphic association like this:</p>
  
  <pre><code>#app/model/transaction.rb 
  def index
    ...
    transactions = self.includes(:ta_type, customer:[:location])
    ...
  end
  </code></pre>
  
  <p>But i need a condition on the customer. This query below is also working.</p>
  
  <pre><code>transactions = self.includes(customer:[:location]).
      where(customer: {office_id: office_id})
  </code></pre>
  
  <p>however the composition of these two does not work</p>
  
  <pre><code>transactions = self.includes(:ta_type, customer:[:location]).
      where(customer: {office_id: office_id})
  </code></pre>
  
  <p>breaks and throws </p>
  
  <pre><code>Completed 500 Internal Server Error in 113ms (ActiveRecord: 3.1ms)
  ActiveRecord::EagerLoadPolymorphicError (Cannot eagerly load the  polymorphic association :ta_type):
  </code></pre>
  
  <p>I found <a href="https://makandracards.com/makandra/28347-eager-loading-polymorphic-associations" rel="nofollow noreferrer">this</a> excellent post describing the problem i have. But i am not able to get it to work. </p>
  
  <p>I tried to use a separated join and a preload together with a join resulting in the same exception.</p>
  
  <pre><code> transactions = self.
       preload(:ta_type, customer:[:location]]).
       joins(:ta_type).
       where(customer: {office_id: office_id})
  </code></pre>
  
  <p>The <code>preload_assocications</code> methods seems to be a good idea, but it was removed from rails 3.0.9. </p>
  
  <p>How is it possible to preload the polymorphic association together with the condition properly?</p>