mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:50:58 +00:00
允许o.Raw(sql).QueryRows(&container) 传入的container包含结构的嵌套
This commit is contained in:
parent
bceefc9075
commit
589f3755f0
@ -493,9 +493,19 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < ind.NumField(); i++ {
|
||||
f := ind.Field(i)
|
||||
fe := ind.Type().Field(i)
|
||||
// define recursive function
|
||||
var recursiveSetField func(rv reflect.Value)
|
||||
recursiveSetField = func(rv reflect.Value) {
|
||||
for i := 0; i < rv.NumField(); i++ {
|
||||
f := rv.Field(i)
|
||||
fe := rv.Type().Field(i)
|
||||
|
||||
// check if the field is a Struct
|
||||
// recursive the Struct type
|
||||
if fe.Type.Kind() == reflect.Struct {
|
||||
recursiveSetField(f)
|
||||
}
|
||||
|
||||
_, tags := parseStructTag(fe.Tag.Get(defaultStructTagName))
|
||||
var col string
|
||||
if col = tags["column"]; col == "" {
|
||||
@ -508,6 +518,10 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// init call the recursive function
|
||||
recursiveSetField(ind)
|
||||
}
|
||||
|
||||
if eTyps[0].Kind() == reflect.Ptr {
|
||||
ind = ind.Addr()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user