I have a custom module that has it's own grid. One of the fields that I pull into the grid is a count of records (notes) that are associated with the entry. It works fine and shows the count in the grid, it sorts fine too, but when I filter I get a message saying it cannot find the column.
Here is the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'note_count' in 'where clause'
And here is the code
class Ssi_Crm_Model_Mysql4_Quote_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
protected function _construct()
{
$this->_init('crm/quote');
}
protected function _initSelect()
{
parent::_initSelect();
$this->_joinUserSet();
return $this;
}
protected function _joinUserSet()
{
$this->getSelect()
->columns("(SELECT COUNT(note) FROM mage_crm_notes WHERE entity_id = main_table.quote_id AND entity_type = 'quote') as note_count")
->join(
array('user'=>$this->getTable('admin/user')),
'main_table.user_id=user.user_id',
array('username' => 'user.username', 'email' => 'user.email'));
return $this;
}