forked from mirror/gorm
Create tables with fields in same order as defined in struct
This commit is contained in:
parent
75819b2bb3
commit
62b447bc9a
|
@ -512,13 +512,18 @@ func (scope *Scope) createJoinTable(field *Field) {
|
|||
|
||||
func (scope *Scope) createTable() *Scope {
|
||||
var sqls []string
|
||||
for _, field := range scope.Fields() {
|
||||
fields := scope.Fields()
|
||||
scopeType := scope.IndirectValue().Type()
|
||||
for i := 0; i < scopeType.NumField(); i++ {
|
||||
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
|
||||
field = fields[field.DBName]
|
||||
if field.IsNormal {
|
||||
sqlTag := scope.sqlTagForField(field)
|
||||
sqls = append(sqls, scope.Quote(field.DBName)+" "+sqlTag)
|
||||
}
|
||||
scope.createJoinTable(field)
|
||||
}
|
||||
}
|
||||
scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v)", scope.QuotedTableName(), strings.Join(sqls, ","))).Exec()
|
||||
return scope
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue