2

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 ) ) )

5

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")));
  • it gets Fatal error: Call to a member function addFieldToSelect() on a non-object – user3245106 Apr 25 '14 at 8:17
  • This means that you module is not properly built. For a CRUD module you need a model, a resource model and a collection model. Most probably you are missing the collection mode. – Marius Apr 25 '14 at 8:19
  • Ok i figure it out that i have file Collections.php insted of Collection.php. What a rookie mistake. Thanks Marius. – user3245106 Apr 25 '14 at 8:48
  • One more question. Can I delete such collection ? – user3245106 Apr 25 '14 at 8:51
  • @user3245106. What do you mean by "delete such collection"? – Marius Apr 25 '14 at 8:52
0

According to problem from comment the soulution was to change

AddFieldToSelect()

to

AddFieldToFilter()

and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.