title: Add a count of related data to each item in a joomla MVC list view
body: <p>I have a custom joomla MVC component. 
  The component has a table of items, 
  and a table of bids to deliver each item. An item can have multiple bids.</p>
  
  <p>i need to show a COUNT of the bids on the items LIST view within each row of the foreach. </p>
  
  <p>What is the BEST way of achieving this? I have tried adding the following to the items model but I am stumped at how to define $id for each item row.</p>
  
  <pre><code>public function getBidsByItemId() { 
      $db = JFactory::getDbo();
      $query = $db-&gt;getQuery(true);
      $query-&gt;select('COUNT(*)');
      $query-&gt;from($db-&gt;quoteName('#__table_bids'));
      $query-&gt;where($db-&gt;quoteName('item_id')." = ".$id);
  
      // Reset the query using our newly populated query object.
      $db-&gt;setQuery($query);
      $count = $db-&gt;loadResult();
  
  }
  </code></pre>
  
  <p>Here you can see the full component/models/items.php to which I added it: <a href="http://ideone.com/yPJHRk" rel="nofollow">http://ideone.com/yPJHRk</a></p>
  
  <p>Grateful for help from the MVC experts out there.</p>