mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve Model function for struct parameter that can retrieve table name tag from
This commit is contained in:
@ -83,21 +83,16 @@ func (c *Core) Table(tableNameOrStruct ...interface{}) *Model {
|
||||
// Model("user u, user_detail ud")
|
||||
// 2. Model name with alias: Model("user", "u")
|
||||
func (c *Core) Model(tableNameOrStruct ...interface{}) *Model {
|
||||
// With feature checks.
|
||||
if len(tableNameOrStruct) > 0 {
|
||||
if _, ok := tableNameOrStruct[0].(string); !ok {
|
||||
return c.With(tableNameOrStruct...)
|
||||
}
|
||||
}
|
||||
// Normal model creation.
|
||||
var (
|
||||
tableStr = ""
|
||||
tableName = ""
|
||||
tableNames = make([]string, len(tableNameOrStruct))
|
||||
)
|
||||
for k, v := range tableNameOrStruct {
|
||||
if s, ok := v.(string); ok {
|
||||
tableNames[k] = s
|
||||
continue
|
||||
} else if tableName = getTableNameFromOrmTag(v); tableName != "" {
|
||||
tableNames[k] = tableName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user