title: How to simulate ActiveRecord Model.count.to_sql
body: <p>I want to display the SQL used in a count. However, <code>Model.count.to_sql</code> will not work because count returns a FixNum that doesn't have a <em>to_sql</em> method. I think the simplest solution is to do this:</p>
  
  <pre><code>Model.where(nil).to_sql.sub(/SELECT.*FROM/, "SELECT COUNT(*) FROM")
  </code></pre>
  
  <p>This creates the same SQL as is used in <code>Model.count</code>, but is it going to cause a problem further down the line? For example, if I add a complicated where clause and some joins.</p>
  
  <p>Is there a better way of doing this?</p>