Invalid Method addFieldToSelect in Magento

collection-filteringcollection;databasemodel

I have this code

$collection = Mage::getModel("news/views");
->addFieldToSelect('post_id', array('eq' =>  $this->getRequest()->getParam("id")));

And when i'm trying to save my post i get en error:

Invalid method Iv_News_Model_Views::addFieldToSelect(Array ( [0] =>
post_id [1] => Array ( [eq] => 13 ) ) )

Best Answer

The addFieldToSelect is available for collection objects. It is defined in Mage_Core_Model_Resource_Db_Collection_Abstract so it is available in all its child classes.

You are calling it on a model object that most probably is a child of Mage_Core_Model_Abstract.

I think you meant to do this:

$collection = Mage::getModel("news/views")->getCollection()
            ->addFieldToSelect('post_id', array('eq' =>  $this->getRequest()->getParam("id")));
Related Topic