Gorm: does gorm support prefix/suffix mapping between struct name and table name?

Created on 23 May 2016  路  5Comments  路  Source: go-gorm/gorm

for example, i want to map struct Employee to table prefix_employee.
xorm has already support this.

Most helpful comment

thanks @pjebs for your reply. the way you provided means i have to define this TableName() for every struct, i think it will be better if gorm has builtin similar mechanism.

All 5 comments

Create a method called TableName() on the struct to give a custom name.

thanks @pjebs for your reply. the way you provided means i have to define this TableName() for every struct, i think it will be better if gorm has builtin similar mechanism.

General mapping rules definition/override would be nice for tables as well as columns.

Overwrite the DefaultTableNameHandler method

@jinzhu It doesn't work in using db.AutoMigrate(Model{}) or db.First(Model{}).
Because DefaultNameHandler is called only from ModelStruct.
If a model implements tabler interface, DefaultNameHandler is never called.

So, I create pull request. Please take a look?
https://github.com/jinzhu/gorm/pull/1688

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rfyiamcool picture rfyiamcool  路  3Comments

Quentin-M picture Quentin-M  路  3Comments

fieryorc picture fieryorc  路  3Comments

easonlin404 picture easonlin404  路  3Comments

superwf picture superwf  路  3Comments