KRay
KRay

Reputation: 71

Magento Fatal error: Call to a member function addFieldToFilter() on a non-object

I am attempting to override a model in a third party extension so I can add a few more columns to the database table it uses and manipulate them. I've added the following in config.xml:

<marketplace>
     <rewrite>
         <userprofile>ZeroBars_Marketplacepayment_Model_Userprofile</userprofile>
     </rewrite>
</marketplace>

and copied the Userprofile.php file into my module's Model folder. The code in Userprofile makes a call to the collection of the previous Model that I am overriding:

public function getPartnerProfileById($partnerId) {
        $data = array();
        if ($partnerId != '') {
            $collection = Mage::getModel('marketplace/userprofile')->getCollection();
            $collection->addFieldToFilter('mageuserid',array('eq'=>$partnerId));

...

and I am now served with a Fatal Error for calling addFieldToFilter. I've tried copying over the files in Mysql4 as well but I am not sure how to go about adding an override for them in config. How can I sleuth out what is going wrong?

Upvotes: 1

Views: 3779

Answers (1)

Amit Bera
Amit Bera

Reputation: 7611

KRay, for get collection of table then you need Define Collection for that model

I you need to class collection file of that module which is fetch all data of the table

Collection file path is Collection.php app/code/yourcodePOol/your pakkage name/Modulename/Model/Resource/Userprofile/

<?php
class YourPackagename_Modulename_Model_Resource_Userprofile_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    protected function _constuct(){
        $this->_init('marketplace/userprofile');    
    }
}

If you using mysql4 as resource model then try

   <?php
    class YourPackagename_Modulename_Model_Mysql4_Userprofile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
    {
        public function _construct()
        {
            $this->_init('marketplace/userprofile');
        }
    } 

Upvotes: 1

Related Questions