mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 21:01:31 +00:00
Merge pull request #312 from bronze1man/pr-orm-querytable-nil-ptr-struct
[orm] QueryTable with nil ptr struct
This commit is contained in:
commit
4ee6cc3022
@ -274,9 +274,7 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
|
|||||||
qs = newQuerySet(o, mi)
|
qs = newQuerySet(o, mi)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := reflect.ValueOf(ptrStructOrTableName)
|
name = getFullName(indirectType(reflect.TypeOf(ptrStructOrTableName)))
|
||||||
ind := reflect.Indirect(val)
|
|
||||||
name = getFullName(ind.Type())
|
|
||||||
if mi, ok := modelCache.getByFN(name); ok {
|
if mi, ok := modelCache.getByFN(name); ok {
|
||||||
qs = newQuerySet(o, mi)
|
qs = newQuerySet(o, mi)
|
||||||
}
|
}
|
||||||
|
@ -473,6 +473,7 @@ The program—and web server—godoc processes Go source files to extract docume
|
|||||||
func TestExpr(t *testing.T) {
|
func TestExpr(t *testing.T) {
|
||||||
user := &User{}
|
user := &User{}
|
||||||
qs := dORM.QueryTable(user)
|
qs := dORM.QueryTable(user)
|
||||||
|
qs = dORM.QueryTable((*User)(nil))
|
||||||
qs = dORM.QueryTable("User")
|
qs = dORM.QueryTable("User")
|
||||||
qs = dORM.QueryTable("user")
|
qs = dORM.QueryTable("user")
|
||||||
num, err := qs.Filter("UserName", "slene").Filter("user_name", "slene").Filter("profile__Age", 28).Count()
|
num, err := qs.Filter("UserName", "slene").Filter("user_name", "slene").Filter("profile__Age", 28).Count()
|
||||||
|
10
orm/utils.go
10
orm/utils.go
@ -231,3 +231,13 @@ func timeParse(dateString, format string) (time.Time, error) {
|
|||||||
func timeFormat(t time.Time, format string) string {
|
func timeFormat(t time.Time, format string) string {
|
||||||
return t.Format(format)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user