因为项目升级时,在model和表的一致性在维护的时候有些麻烦,我想能不能在AR中留个接口,开发者可以自定义当表不存在时如何处理.
我model中定义了字段集 fields()及索引集tableKeys().我现在做一个组件扫描了所有的model,然后通过model的字段及索引配置自动完成系统升级需要对表做的一些改动或修复.现在的情况是表不存在时无法自动创建表.当然model中写__construct可以也实现,但导致每次model实例化时都做查询判断,这可不理想,应该不是很推荐吧!而扫描组件只会在需求的时候人工触发一次.
public function tableName()
{
return '{{tag}}';
}
public function fields(){
return array(
'id'=>'bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT "流水号"',
'name'=>'varchar(32) NOT NULL DEFAULT "" COMMENT "名称"',
'fullspell'=>'varchar(200) NOT NULL COMMENT "全拼"',
'simplspell'=>'varchar(200) NOT NULL COMMENT "简拼"',
);
}
public function tableKeys(){
return array(
'word'=>'word_index_1',
'fullspell'=>'fullspell_index_1',
'simplspell'=>'simplspell_index_1',
);
}