diff --git a/schema/schema.go b/schema/schema.go index 57bab7fd..db236797 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -338,7 +338,7 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam if _, embedded := schema.cacheStore.Load(embeddedCacheKey); !embedded { for _, field := range schema.Fields { - if field.DataType == "" && (field.Creatable || field.Updatable || field.Readable) { + if field.DataType == "" && field.GORMDataType == "" && (field.Creatable || field.Updatable || field.Readable) { if schema.parseRelation(field); schema.err != nil { return schema, schema.err } else { diff --git a/schema/schema_test.go b/schema/schema_test.go index 45e152e9..a7115f60 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -19,6 +19,22 @@ func TestParseSchema(t *testing.T) { checkUserSchema(t, user) } +func TestParseSchemaWithMap(t *testing.T) { + type User struct { + tests.User + Attrs map[string]string `gorm:"type:Map(String,String);"` + } + + user, err := schema.Parse(&User{}, &sync.Map{}, schema.NamingStrategy{}) + if err != nil { + t.Fatalf("failed to parse user with map, got error %v", err) + } + + if field := user.FieldsByName["Attrs"]; field.DataType != "Map(String,String)" { + t.Errorf("failed to parse user field Attrs") + } +} + func TestParseSchemaWithPointerFields(t *testing.T) { user, err := schema.Parse(&User{}, &sync.Map{}, schema.NamingStrategy{}) if err != nil {