title: Rails Query - Join on non-primary column
body: <p>I have three models: <code>Foo</code>, <code>Bar</code> and <code>Profile</code>. The first two models reference <code>Profile</code>.</p>
  <p>I would like join Foo and Bar without having to join Profile e.g.</p>
  <pre class="lang-rb prettyprint-override"><code>class Foo &lt; ApplicationRecord
    belongs_to :profile
  end
  
  class Bar &lt; ApplicationRecord
    belongs_to :profile
  end
  
  class Profile &lt; ApplicationRecord
  end
  </code></pre>
  <p>The SQL would look something like:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT *
  FROM foo 
  INNER JOIN bar ON foo.profile_id = bar.profile_id
  </code></pre>
  <p>I could do the following, but I don't want to join <code>Profile</code> as it's a much larger table.</p>
  <pre class="lang-rb prettyprint-override"><code>Foo.joins(profile: :bar)
  </code></pre>