gogo-gorm

How to get a table name from a model in 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...

Solution

  • Like this:

    tableName := db.NewScope(model).GetModelStruct().TableName(db)
    

    Update: Shorter

    tableName := db.NewScope(model).TableName()