我有一个我们将调用的自定义mysql表,module_identifiers以及我模块中名为Identifiers的相应模型.这是我的设置脚本:
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$installer->getTable('module_identifiers')}` (
`module_identifier_id` int(11) NOT NULL AUTO_INCREMENT,
`identifier` varchar(255) NOT NULL,
`customer_id` int(11) unsigned NOT NULL,
`profile_name` varchar(100) NOT NULL,
`provider` varchar(50) NOT NULL,
PRIMARY KEY (`module_identifier_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
");
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)
在我的Module/Model/Identifiers.php中
class Namespace_Module_Model_Identifiers extends Mage_Core_Model_Abstract {
protected function _construct() {
$this->_init('module/identifiers');
}
}
Run Code Online (Sandbox Code Playgroud)
在Module/Model/Mysql4/Identifiers.php中
class Namespace_Module_Model_Mysql4_Identifiers extends Mage_Core_Model_Mysql4_Abstract {
protected function _construct() {
$this->_init('module/identifiers', 'module_identifier_id');
}
}
Run Code Online (Sandbox Code Playgroud)
所以,当我想写这个表时,我一直这样做:
Mage::getModel('module/identifiers')
->setIdentifier($profile['identifier'])
->setCustomerId($customer_id)
->save();
Run Code Online (Sandbox Code Playgroud)
在我添加了provider和profile_name列之前,这一点很有效,而且这些列永远不会更新:
Mage::getModel('module/identifiers')
->setIdentifier($profile['identifier'])
->setProvider($profile['provider'])
->setProfileName($profile['profile_name']) …Run Code Online (Sandbox Code Playgroud)