This commit is contained in:
John Guo 2021-03-24 22:04:04 +08:00
parent 54395b39a6
commit bb6883213f
2 changed files with 6 additions and 7 deletions

View File

@ -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)
}

View File

@ -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)