title: rails select and include
body: <p>Can anyone explain this?</p>
  
  <pre><code>Project.includes([:user, :company])
  </code></pre>
  
  <p>This executes 3 queries, one to fetch projects, one to fetch users for those projects and one to fetch companies.</p>
  
  <pre><code>Project.select("name").includes([:user, :company])
  </code></pre>
  
  <p>This executes 3 queries, and completely ignores the select bit.</p>
  
  <pre><code>Project.select("user.name").includes([:user, :company])
  </code></pre>
  
  <p>This executes 1 query with proper left joins. And still completely ignores the select. </p>
  
  <p>It would seem to me that rails ignores select with includes. Ok fine, but why when I put a related model in select does it switch from issuing 3 queries to issuing 1 query?</p>
  
  <p>Note that the 1 query is what I want, I just can't imagine this is the right way to get it nor why it works, but I'm not sure how else to get the results in one query (.joins seems to only use INNER JOIN which I do not in fact want, and when I manually specifcy the join conditions to .joins the search gem we're using freaks out as it tries to re-add joins with the same name).</p>