title: Rails ActiveRecord Join Query With conditions
body: <p>I have following SQL Query:</p>
  
  <pre><code>SELECT campaigns.* , campaign_countries.points, offers.image
  FROM campaigns
  JOIN campaign_countries ON campaigns.id = campaign_countries.campaign_id
  JOIN countries ON campaign_countries.country_id = countries.id
  JOIN offers ON campaigns.offer_id = offers.id
  WHERE countries.code = 'US'
  </code></pre>
  
  <p>This works perfectly well. I want its rails active record version some thing like:</p>
  
  <pre><code>Campaign.includes(campaign_countries: :country).where(countries: {code: "US"})
  </code></pre>
  
  <p>Above code runs more or less correct query (did not try to include offers table), issue is returned result is collection of Campaign objects so obviously it does not include Points</p>
  
  <p>My tables are:</p>
  
  <pre><code>campaigns --HAS_MANY--&lt; campaign_countries --BELONGS_TO--&lt; countries
  campaigns --BELONGS_TO--&gt; offers
  </code></pre>
  
  <p>Any suggestions to write AR version of this SQL? I don't want to use SQL statement in my code.</p>