title: Multiple Inner Joins with Polymorphic Association
body: <p>I have the following polymorphic association...</p>
  
  <pre><code>class Activity &lt; ActiveRecord::Base
    belongs_to :owner, polymorphic: true
  end
  
  class User &lt; ActiveRecord::Base
    has_many :activities, as: :owner
  end
  
  class Manager &lt; ActiveRecord::Base
    has_many :activities, as: :owner
  end    
  </code></pre>
  
  <p>I am trying to make a query whereby it only pulls out the activities where the owner (user or manager) has <code>visible</code> set to <code>true</code>.</p>
  
  <p>I have figured out that if I want to do this for one of the owners, I can do this as follows...</p>
  
  <pre><code>Activity.joins("INNER JOIN users ON activities.owner_id = users.id").where(:activities =&gt; {:owner_type =&gt; 'User'}).where(:users =&gt; {:visible =&gt; true})
  </code></pre>
  
  <p>But I cannot figure out how to do it for both. Can anyone help?</p>