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.
i need to show a COUNT of the bids on the items LIST view within each row of the foreach.
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.
public function getBidsByItemId() {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__table_bids'));
$query->where($db->quoteName('item_id')." = ".$id);
// Reset the query using our newly populated query object.
$db->setQuery($query);
$count = $db->loadResult();
}
Here you can see the full component/models/items.php to which I added it: http://ideone.com/yPJHRk
Grateful for help from the MVC experts out there.