title: Rails 4: Dynamic table name possible in `where` on `has_many :through`?
body: <p>I have an association:</p>
  
  <pre><code>has_many :regions_deployed, -&gt; { where(taggings: { scope: 'deployed' }) },
  :through =&gt; :taggings, :source =&gt; :choice_filter, :source_type =&gt; "Region"
  </code></pre>
  
  <p>This usually works, except when it is used in the <code>joins</code> clause of a named scope, chained to other named scopes that also join on <code>taggings</code>. Then Postgres aliases the table name <code>taggings</code>, but the <code>where(taggings: { scope: 'deployed' }</code> does not reflect that alias. How can I specify a dynamic table name inside <code>where</code>?</p>
  
  <p>I think this question is closely related, but can't get it: <a href="https://stackoverflow.com/questions/24921729/join-the-same-table-twice-with-conditions">Join the same table twice with conditions</a></p>