fix: restore previous behaviour
This commit is contained in:
parent
b8891f5f78
commit
2757ac7357
@ -300,11 +300,13 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam
|
||||
field.AutoIncrement = true
|
||||
}
|
||||
case String:
|
||||
if !field.HasDefaultValue || field.DefaultValueInterface != nil {
|
||||
schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field)
|
||||
}
|
||||
if _, ok := field.TagSettings["PRIMARYKEY"]; !ok {
|
||||
if !field.HasDefaultValue || field.DefaultValueInterface != nil {
|
||||
schema.FieldsWithDefaultDBValue = append(schema.FieldsWithDefaultDBValue, field)
|
||||
}
|
||||
|
||||
field.HasDefaultValue = true
|
||||
field.HasDefaultValue = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,11 +341,6 @@ func TestStringPrimaryKeyDefault(t *testing.T) {
|
||||
Code string
|
||||
Name string
|
||||
}
|
||||
type ProductWithNamedPrimaryKey struct {
|
||||
ProductID string `gorm:"primaryKey"`
|
||||
Code string
|
||||
Name string
|
||||
}
|
||||
|
||||
product, err := schema.Parse(&Product{}, &sync.Map{}, schema.NamingStrategy{})
|
||||
if err != nil {
|
||||
@ -362,20 +357,4 @@ func TestStringPrimaryKeyDefault(t *testing.T) {
|
||||
if !isInDefault {
|
||||
t.Errorf("ID should be fields with default")
|
||||
}
|
||||
|
||||
productWithNamedPrimaryKey, err := schema.Parse(&ProductWithNamedPrimaryKey{}, &sync.Map{}, schema.NamingStrategy{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse product struct with composite primary key, got error %v", err)
|
||||
}
|
||||
|
||||
isInDefault = false
|
||||
for _, field := range productWithNamedPrimaryKey.FieldsWithDefaultDBValue {
|
||||
if field.Name == "ProductID" {
|
||||
isInDefault = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isInDefault {
|
||||
t.Errorf("ProductID should be fields with default")
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,6 @@ func TestStringPrimaryKeyDefault(t *testing.T) {
|
||||
Code string
|
||||
Name string
|
||||
}
|
||||
type ProductWithNamedPrimaryKey struct {
|
||||
ProductID uuid.UUID `gorm:"primaryKey"`
|
||||
Code string
|
||||
Name string
|
||||
}
|
||||
|
||||
product, err := schema.Parse(&Product{}, &sync.Map{}, schema.NamingStrategy{})
|
||||
if err != nil {
|
||||
@ -35,20 +30,4 @@ func TestStringPrimaryKeyDefault(t *testing.T) {
|
||||
if !isInDefault {
|
||||
t.Errorf("ID should be fields with default")
|
||||
}
|
||||
|
||||
productWithNamedPrimaryKey, err := schema.Parse(&ProductWithNamedPrimaryKey{}, &sync.Map{}, schema.NamingStrategy{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse product struct with composite primary key, got error %v", err)
|
||||
}
|
||||
|
||||
isInDefault = false
|
||||
for _, field := range productWithNamedPrimaryKey.FieldsWithDefaultDBValue {
|
||||
if field.Name == "ProductID" {
|
||||
isInDefault = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isInDefault {
|
||||
t.Errorf("ProductID should be fields with default")
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func TestUpsert(t *testing.T) {
|
||||
}
|
||||
|
||||
r := DB.Session(&gorm.Session{DryRun: true}).Clauses(clause.OnConflict{UpdateAll: true}).Create(&RestrictedLanguage{Code: "upsert_code", Name: "upsert_name", Lang: "upsert_lang"})
|
||||
if !regexp.MustCompile(`INTO .restricted_languages. .*\(.name.,.lang.,.code.\) .* (SET|UPDATE) .name.=.*.name. RETURNING .code.\W*$`).MatchString(r.Statement.SQL.String()) {
|
||||
if !regexp.MustCompile(`INTO .restricted_languages. .*\(.code.,.name.,.lang.,\) .* (SET|UPDATE) .name.=.*.name.\W*$`).MatchString(r.Statement.SQL.String()) {
|
||||
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user