title: Optimizing query with large result set
body: <p>I have a CakePHP model, let's call it <code>Thing</code> which has an associated model called <code>ItemView</code>. <code>ItemView</code> represents one page view of the <code>Thing</code> item. I want to display how many times <code>Thing</code> has been viewed, so I do the following in my view:</p>
  
  <pre><code>&lt;?php echo count($thing['ItemView']); ?&gt;
  </code></pre>
  
  <p>This works, however as time goes on the result set of this query is going to get huge, as it's currently being returned like so:</p>
  
  <pre><code>array(
      'Thing' =&gt; array(
          'id' =&gt; '1',
          'thing' =&gt; 'something'
      ),
      'ItemView' =&gt; array(
          (int) 0 =&gt; array(
              'id' =&gt; '1',
              'thing_id' =&gt; 1,
              'created' =&gt; '2013-09-21 19:25:39',
              'ip_address' =&gt; '127.0.0.1'
          ),
          (int) 1 =&gt; array(
              'id' =&gt; '1',
              'thing_id' =&gt; 1,
              'created' =&gt; '2013-09-21 19:25:41',
              'ip_address' =&gt; '127.0.0.1'
          ),
          // etc...
      )
  )
  </code></pre>
  
  <p>How can I adapt the model <code>find()</code> to retrieve something like so:</p>
  
  <pre><code>array(
      'Thing' =&gt; array(
          'id' =&gt; '1',
          'thing' =&gt; 'something',
          'views' =&gt; 2
      )
  )
  </code></pre>
  
  <p>without loading the entire <code>ItemView</code> relation into memory?</p>
  
  <p>Thanks!</p>