forked from mirror/gorm
Merge pull request #280 from ryanss/master
Create tables with fields in same order as defined in struct
This commit is contained in:
commit
8482d0a121
|
@ -512,12 +512,17 @@ func (scope *Scope) createJoinTable(field *Field) {
|
||||||
|
|
||||||
func (scope *Scope) createTable() *Scope {
|
func (scope *Scope) createTable() *Scope {
|
||||||
var sqls []string
|
var sqls []string
|
||||||
for _, field := range scope.Fields() {
|
fields := scope.Fields()
|
||||||
if field.IsNormal {
|
scopeType := scope.IndirectValue().Type()
|
||||||
sqlTag := scope.sqlTagForField(field)
|
for i := 0; i < scopeType.NumField(); i++ {
|
||||||
sqls = append(sqls, scope.Quote(field.DBName)+" "+sqlTag)
|
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.createJoinTable(field)
|
|
||||||
}
|
}
|
||||||
scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v)", scope.QuotedTableName(), strings.Join(sqls, ","))).Exec()
|
scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v)", scope.QuotedTableName(), strings.Join(sqls, ","))).Exec()
|
||||||
return scope
|
return scope
|
||||||
|
|
Loading…
Reference in New Issue