mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 10:01:28 +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 {
|
} else {
|
||||||
for i := 0; i < ind.NumField(); i++ {
|
// define recursive function
|
||||||
f := ind.Field(i)
|
var recursiveSetField func(rv reflect.Value)
|
||||||
fe := ind.Type().Field(i)
|
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))
|
_, tags := parseStructTag(fe.Tag.Get(defaultStructTagName))
|
||||||
var col string
|
var col string
|
||||||
if col = tags["column"]; col == "" {
|
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 {
|
if eTyps[0].Kind() == reflect.Ptr {
|
||||||
ind = ind.Addr()
|
ind = ind.Addr()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user