Magento – I am getting error on save() method of a model

model

I am getting this error on save method of a model.

Fatal error: Call to a member function beginTransaction() on a
non-object in
/home/public_html/app/code/core/Mage/Core/Model/Abstract.php on line
313

$warranty = Mage::getModel('warrany/warrantydata');
$warranty->setOrderId($order_id);
$warranty->setSignifydScore($signifyd_score);
$warranty->setSignifydData(utf8_encode(serialize($data)));
$warranty->save();

I have this added xml for model

    <models>
    <warranty>
      <class>Website_Warranty_Model</class>
      <resourceModel>warranty_mysql4</resourceModel>
        </warranty>
       <warranty_mysql4>
              <class>Website_Warranty_Model_Mysql4</class>
          <entities>
            <warrantydata>
               <table>warrantydata</table>
        </warrantydata>
          </entities>
          </warranty_mysql4>
   </models>

i also have the collection and model file

class Website_Warranty_Model_Warrantydata extends Mage_Core_Model_Abstract{}

class Website_Warranty_Model_Mysql4_Warrantydata extends Mage_Core_Model_Mysql4_Abstract {}

Best Answer

In your resource model Website_Warranty_Model_Mysql4_Warrantydata you need to add this method :

public function _construct(){
    $this->_init('warranty/warrantydata', 'entity_id'); //the second parameter must be the primary key in your warrantydata table. If it's not `entity_id` then change it
}

and in your model class Website_Warranty_Model_Warrantydata you need this method:

public function _construct(){
    parent::_construct();
    $this->_init('warranty/warrantydata');
}