stevenyang1011
11/15/2017 - 9:00 PM

Magento Model get rid of the default primary key

Magento Model get rid of the default primary key

//Magento Model comes with a autoincrement key by default, however, in my case I dont need that.
//And the problem is that it blocks me to creata record by $model->setId(xxx)->save();

//Solution: add $this->_isPkAutoIncrement = false; to resource model

class Ecommistry_Indexerforapi_Model_Resource_Productstack extends Mage_Core_Model_Resource_Db_Abstract
{

    protected function _construct()
    {
        $this->_init('ecommistry_indexerforapi/product_stack', 'id');
        $this->_isPkAutoIncrement = false;
    }

}

// and now ->setId(xxx)->save() is working