mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 19:57:40 +08:00
This commit is contained in:
parent
26d2a98fb1
commit
467a5c1093
@ -24,12 +24,15 @@ func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fie
|
||||
)
|
||||
|
||||
if fieldValueKind == reflect.Slice {
|
||||
fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue),
|
||||
map[string]string{
|
||||
"[": "{",
|
||||
"]": "}",
|
||||
},
|
||||
)
|
||||
// For pgsql, json or jsonb require '[]'
|
||||
if !gstr.Contains(fieldType, "json") {
|
||||
fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue),
|
||||
map[string]string{
|
||||
"[": "{",
|
||||
"]": "}",
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
return d.Core.ConvertValueForField(ctx, fieldType, fieldValue)
|
||||
}
|
||||
|
@ -103,3 +103,42 @@ func Test_Issue3632(t *testing.T) {
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3671
|
||||
func Test_Issue3671(t *testing.T) {
|
||||
type SubMember struct {
|
||||
Seven string
|
||||
Eight int64
|
||||
}
|
||||
type Member struct {
|
||||
One []int64 `json:"one" orm:"one"`
|
||||
Two [][]string `json:"two" orm:"two"`
|
||||
Three []string `json:"three" orm:"three"`
|
||||
Four []int64 `json:"four" orm:"four"`
|
||||
Five []SubMember `json:"five" orm:"five"`
|
||||
}
|
||||
var (
|
||||
sqlText = gtest.DataContent("issues", "issue3671.sql")
|
||||
table = fmt.Sprintf(`%s_%d`, TablePrefix+"issue3632", gtime.TimestampNano())
|
||||
)
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(sqlText, table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
dao = db.Model(table)
|
||||
member = Member{
|
||||
One: []int64{1, 2, 3},
|
||||
Two: [][]string{{"a", "b"}, {"c", "d"}},
|
||||
Three: []string{"x", "y", "z"},
|
||||
Four: []int64{1, 2, 3},
|
||||
Five: []SubMember{{Seven: "1", Eight: 2}, {Seven: "3", Eight: 4}},
|
||||
}
|
||||
)
|
||||
|
||||
_, err := dao.Ctx(ctx).Data(&member).Insert()
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
8
contrib/drivers/pgsql/testdata/issues/issue3671.sql
vendored
Normal file
8
contrib/drivers/pgsql/testdata/issues/issue3671.sql
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE "public"."%s"
|
||||
(
|
||||
"one" int8[] NOT NULL,
|
||||
"two" text[][] NOT NULL,
|
||||
"three" jsonb,
|
||||
"four" json,
|
||||
"five" jsonb
|
||||
);
|
Loading…
Reference in New Issue
Block a user