Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
589f3755
Commit
589f3755
authored
May 12, 2017
by
sunxinle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
允许o.Raw(sql).QueryRows(&container) 传入的container包含结构的嵌套
parent
bceefc90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
orm_raw.go
orm/orm_raw.go
+25
-11
No files found.
orm/orm_raw.go
View file @
589f3755
...
...
@@ -493,19 +493,33 @@ 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
)
_
,
tags
:=
parseStructTag
(
fe
.
Tag
.
Get
(
defaultStructTagName
))
var
col
string
if
col
=
tags
[
"column"
];
col
==
""
{
col
=
snakeString
(
fe
.
Name
)
}
if
v
,
ok
:=
columnsMp
[
col
];
ok
{
value
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
.
Interface
()
o
.
setFieldValue
(
f
,
value
)
// 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
==
""
{
col
=
snakeString
(
fe
.
Name
)
}
if
v
,
ok
:=
columnsMp
[
col
];
ok
{
value
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
.
Interface
()
o
.
setFieldValue
(
f
,
value
)
}
}
}
// init call the recursive function
recursiveSetField
(
ind
)
}
if
eTyps
[
0
]
.
Kind
()
==
reflect
.
Ptr
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment