title: Replacement for "has_many ... counter_sql" in Rails 4.1
body: <p>Rails 4.1 removed the <code>counter_sql</code> from <code>has_many</code> associations, so the following does no longer work:</p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
  
    has_many :backers,
      -&gt; { select('COMPLEX SQL QUERY') },
      through: :pledges,
      source: :backer,
      counter_sql: proc { "COMPLEX COUNT SQL QUERY" }
  
    (...)
  end
  </code></pre>
  
  <p>I need a <code>counter_sql</code> here since with the COMPLEX SQL QUERY in <code>select</code>, AR does not build valid SQL when I do <code>project.backers.count</code>.</p>
  
  <p>To fix this, I'd move this to a method like so:</p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
  
    has_many :backers,
      -&gt; { select('COMPLEX SQL QUERY') },
      through: :pledges,
      source: :backer
  
    def backers_count
      self.class.count_by_sql 'COMPLEX SQL QUERY'
    end
  
    (...)
  end
  </code></pre>
  
  <p>Is this a good way to go or are there better approaches?</p>