diff --git a/database/gdb/gdb_type_result.go b/database/gdb/gdb_type_result.go index 776cb0657..a5800ece9 100644 --- a/database/gdb/gdb_type_result.go +++ b/database/gdb/gdb_type_result.go @@ -189,5 +189,5 @@ func (r Result) RecordKeyUint(key string) map[uint]Record { // Structs converts `r` to struct slice. // Note that the parameter `pointer` should be type of *[]struct/*[]*struct. func (r Result) Structs(pointer interface{}) (err error) { - return gconv.StructsTag(r, pointer, OrmTagForStruct) + return gconv.StructsTag(r.List(), pointer, OrmTagForStruct) } diff --git a/database/gdb/gdb_z_mysql_struct_test.go b/database/gdb/gdb_z_mysql_struct_test.go index b1b7e7efe..67a1858cb 100644 --- a/database/gdb/gdb_z_mysql_struct_test.go +++ b/database/gdb/gdb_z_mysql_struct_test.go @@ -8,7 +8,6 @@ package gdb_test import ( "database/sql" - "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/gtime" "github.com/gogf/gf/test/gtest" @@ -383,7 +382,7 @@ func Test_Model_Scan_CustomType_String(t *testing.T) { err := db.Model(table).Fields("Passport").Order("id asc").Scan(&sts) t.AssertNil(err) t.Assert(len(sts), TableSize) - t.Assert(sts[0], "user_1") + t.Assert(sts[0].Passport, "user_1") }) } @@ -398,11 +397,11 @@ type User struct { func (user *User) UnmarshalValue(value interface{}) error { switch result := value.(type) { case map[string]interface{}: - user.Id = result["id"].(gdb.Value).Int() - user.Passport = result["passport"].(gdb.Value).String() + user.Id = result["id"].(int) + user.Passport = result["passport"].(string) user.Password = "" - user.Nickname = result["nickname"].(gdb.Value).String() - user.CreateTime = result["create_time"].(gdb.Value).GTime() + user.Nickname = result["nickname"].(string) + user.CreateTime = gtime.New(result["create_time"]) return nil default: return gconv.Struct(value, user)