title: How do you use COUNT(*) with find('list') in CakePHP 3?
body: <p>In CakePHP 3, I had a model called Articles and a field called 'subject', and I ran into a roadblock trying to retrieve a list of the 100 most commonly-used article subjects.</p>
  
  <p>The following code's resulting SQL selected <em>all</em> of the possible fields and <em>not</em> <code>COUNT(*)</code>:</p>
  
  <pre><code>$articles-&gt;find('list', [
      'keyField' =&gt; 'subject',
      'valueField' =&gt; 'COUNT(*)'
  ])
  -&gt;group('subject')
  -&gt;order(['COUNT(*)' =&gt; 'DESC'])
  -&gt;limit(100)
  -&gt;toArray();
  </code></pre>
  
  <p>Then I remembered <a href="http://book.cakephp.org/3.0/en/orm/query-builder.html#using-sql-functions" rel="noreferrer">"CakePHP’s ORM offers abstraction for some commonly used SQL functions."</a>. But the following code resulted in "Error: Function name must be a string":</p>
  
  <pre><code>$countFunc = $this-&gt;find()-&gt;func()-&gt;count('*');
  $articles-&gt;find('list', [
      'keyField' =&gt; 'subject',
      'valueField' =&gt; $countFunc
  ])
  -&gt;group('subject')
  -&gt;order([$countFunc =&gt; 'DESC'])
  -&gt;limit(100)
  -&gt;toArray();
  </code></pre>