go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Can we put the table structure in to XXXmodel.go when generating models with goctl?

Open kissIce opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. 我尝试在项目中引入gorm,但是在用goctl生成实体结构体的时候遇到点问题。比如我想定义gorm的关联关系,却不能修改xxxModel_gen.go。因为会提示该文件是自动生成的。 如下图 image

但是我想去修改自定义模板也没办法实现,我尝试把goctl模板里 Model_gen.tpl的{{.types}}或者type.tpl里面的{{.field}}复制到Model.tpl里面,生成的时候会报错。如下图 image

而且因为每个表的关联关系不一样,没办法通过修改Model_gen.tpl模板去定义使用。

Describe the solution you'd like 我认为可以把表的实体结构体放到生成的 XXXmodel.go文件里,因为我们可以正常修改这个文件。同时这样也能保证XXXModel_gen.go可以正常使用,对现有的不会有影响 我期望的是生成这样的,比如 数据库 area表 生成的type Area struct 能放在areaModel.go里面,而不是在areaModel_gen.go里面 image

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

kissIce avatar Feb 04 '24 06:02 kissIce