mirror of https://github.com/go-gorm/gorm.git
Fix Error when using custom columns with ignored fields
This commit is contained in:
parent
1888335b6e
commit
b33f30714b
|
@ -59,5 +59,7 @@ func TestCustomizeColumn(t *testing.T) {
|
|||
|
||||
func TestCustomColumnAndIgnoredFieldClash(t *testing.T) {
|
||||
DB.DropTable(&CustomColumnAndIgnoredFieldClash{})
|
||||
DB.AutoMigrate(&CustomColumnAndIgnoredFieldClash{})
|
||||
if err := DB.AutoMigrate(&CustomColumnAndIgnoredFieldClash{}).Error; err != nil {
|
||||
t.Errorf("Should not raise error: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -582,12 +582,16 @@ func (scope *Scope) createTable() *Scope {
|
|||
continue
|
||||
}
|
||||
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)
|
||||
name := field.Name
|
||||
for _, field := range fields {
|
||||
if field.Name == name {
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue