Paginate sorting by association count in cakephp
<p>I would like to sort a paginate by the count of associated objects.</p>

<p>I tried to use something like:</p>

<pre><code>$query=$this-&gt;Posts-&gt;find('all',['contain'=&gt;['Comments'=&gt;
function ($q) {return $q -&gt; count();  } ]]);
</code></pre>