donglu4159 2018-08-24 07:26
浏览 4776
已采纳

如何从gorm中的模型获取表名?

Is it possible to get model's table name? I see that it's possible to get it from ModelStruct but I don't know how to do it correctly. I didn't find any initializations for this structure.

user := User{}
tableName := db...
  • 写回答

1条回答 默认 最新

  • drd99007 2018-08-24 07:37
    关注

    Like this:

    tableName := db.NewScope(model).GetModelStruct().TableName(db)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?