Handle data type cases

This commit is contained in:
Jinzhu 2020-06-19 22:51:46 +08:00
parent e3292b3b41
commit d4d339f3b5
2 changed files with 7 additions and 2 deletions

View File

@ -224,7 +224,12 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
}
if val, ok := field.TagSettings["TYPE"]; ok {
field.DataType = DataType(val)
switch DataType(strings.ToLower(val)) {
case Bool, Int, Uint, Float, String, Time, Bytes:
field.DataType = DataType(strings.ToLower(val))
default:
field.DataType = DataType(val)
}
}
if v, ok := field.TagSettings["AUTOCREATETIME"]; ok || (field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) {

View File

@ -107,7 +107,7 @@ func TestEmbeddedPointerTypeStruct(t *testing.T) {
}
type Content struct {
Content interface{} `gorm:"type:string"`
Content interface{} `gorm:"type:String"`
}
func (c Content) Value() (driver.Value, error) {