Magento: Save data in database model without an auto_increment primary key
By
default, Magento expects the primary key with auto_increment field. But sometimes we don't need of auto increment for our primary key as per client requirement.
Save model data without auto-increment as follows:
Save model data without auto-increment as follows:
class
MyNamespace_MyCustomModule_Model_Resource_
MyCustomModuleModel
extends
Mage_Core_Model_Mysql4_Abstract {
public
function
_construct() {
// Table resource, primary key
$this
->_init(
'mycustommodule/mycustommodulemodel'
,
'mycustommodule_id'
);
// The primary key is not an auto_increment field
$this
->_isPkAutoIncrement = false;
}
}
Here we just set the '
_isPkAutoIncrement ' variable as 'false'.
Clear the cache before execute the file.
Note: You will know more about Magento & Download latest version of Magento from http://www.magentocommerce.com/
Note: You will know more about Magento & Download latest version of Magento from http://www.magentocommerce.com/
Magento: Save data in database model without an auto_increment primary key
Reviewed by Web Technology Funda
on
2:13:00 AM
Rating:
No comments