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) {
|
func TestCustomColumnAndIgnoredFieldClash(t *testing.T) {
|
||||||
DB.DropTable(&CustomColumnAndIgnoredFieldClash{})
|
DB.DropTable(&CustomColumnAndIgnoredFieldClash{})
|
||||||
DB.AutoMigrate(&CustomColumnAndIgnoredFieldClash{})
|
if err := DB.AutoMigrate(&CustomColumnAndIgnoredFieldClash{}).Error; err != nil {
|
||||||
|
t.Errorf("Should not raise error: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -582,7 +582,9 @@ func (scope *Scope) createTable() *Scope {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
|
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
|
||||||
field = fields[field.DBName]
|
name := field.Name
|
||||||
|
for _, field := range fields {
|
||||||
|
if field.Name == name {
|
||||||
if field.IsNormal {
|
if field.IsNormal {
|
||||||
sqlTag := scope.sqlTagForField(field)
|
sqlTag := scope.sqlTagForField(field)
|
||||||
sqls = append(sqls, scope.Quote(field.DBName)+" "+sqlTag)
|
sqls = append(sqls, scope.Quote(field.DBName)+" "+sqlTag)
|
||||||
|
@ -590,6 +592,8 @@ func (scope *Scope) createTable() *Scope {
|
||||||
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