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
4ee6cc30
Commit
4ee6cc30
authored
Nov 24, 2013
by
slene
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #312 from bronze1man/pr-orm-querytable-nil-ptr-struct
[orm] QueryTable with nil ptr struct
parents
a0dff914
ceb4aa9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
orm.go
orm/orm.go
+1
-3
orm_test.go
orm/orm_test.go
+1
-0
utils.go
orm/utils.go
+10
-0
No files found.
orm/orm.go
View file @
4ee6cc30
...
...
@@ -274,9 +274,7 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
qs
=
newQuerySet
(
o
,
mi
)
}
}
else
{
val
:=
reflect
.
ValueOf
(
ptrStructOrTableName
)
ind
:=
reflect
.
Indirect
(
val
)
name
=
getFullName
(
ind
.
Type
())
name
=
getFullName
(
indirectType
(
reflect
.
TypeOf
(
ptrStructOrTableName
)))
if
mi
,
ok
:=
modelCache
.
getByFN
(
name
);
ok
{
qs
=
newQuerySet
(
o
,
mi
)
}
...
...
orm/orm_test.go
View file @
4ee6cc30
...
...
@@ -473,6 +473,7 @@ The program—and web server—godoc processes Go source files to extract docume
func
TestExpr
(
t
*
testing
.
T
)
{
user
:=
&
User
{}
qs
:=
dORM
.
QueryTable
(
user
)
qs
=
dORM
.
QueryTable
((
*
User
)(
nil
))
qs
=
dORM
.
QueryTable
(
"User"
)
qs
=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
Filter
(
"UserName"
,
"slene"
)
.
Filter
(
"user_name"
,
"slene"
)
.
Filter
(
"profile__Age"
,
28
)
.
Count
()
...
...
orm/utils.go
View file @
4ee6cc30
...
...
@@ -231,3 +231,13 @@ func timeParse(dateString, format string) (time.Time, error) {
func
timeFormat
(
t
time
.
Time
,
format
string
)
string
{
return
t
.
Format
(
format
)
}
func
indirectType
(
v
reflect
.
Type
)
reflect
.
Type
{
switch
v
.
Kind
()
{
case
reflect
.
Ptr
:
return
indirectType
(
v
.
Elem
())
default
:
return
v
}
return
v
}
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