Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
906637ae
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
906637ae
编写于
12月 15, 2015
作者:
P
Pelle Johnsen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue with reverse(many) for models with custom pk
- Also add test covering the issue
上级
332fa442
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
1 deletion
+89
-1
orm/db_tables.go
orm/db_tables.go
+1
-1
orm/models_test.go
orm/models_test.go
+18
-0
orm/orm_test.go
orm/orm_test.go
+70
-0
未找到文件。
orm/db_tables.go
浏览文件 @
906637ae
...
@@ -186,7 +186,7 @@ func (t *dbTables) getJoinSQL() (join string) {
...
@@ -186,7 +186,7 @@ func (t *dbTables) getJoinSQL() (join string) {
table
=
jt
.
mi
.
table
table
=
jt
.
mi
.
table
switch
{
switch
{
case
jt
.
fi
.
fieldType
==
RelManyToMany
||
jt
.
fi
.
reverse
&&
jt
.
fi
.
reverseFieldInfo
.
fieldType
==
RelManyToMany
:
case
jt
.
fi
.
fieldType
==
RelManyToMany
||
jt
.
fi
.
fieldType
==
RelReverseMany
||
jt
.
fi
.
reverse
&&
jt
.
fi
.
reverseFieldInfo
.
fieldType
==
RelManyToMany
:
c1
=
jt
.
fi
.
mi
.
fields
.
pk
.
column
c1
=
jt
.
fi
.
mi
.
fields
.
pk
.
column
for
_
,
ffi
:=
range
jt
.
mi
.
fields
.
fieldsRel
{
for
_
,
ffi
:=
range
jt
.
mi
.
fields
.
fieldsRel
{
if
jt
.
fi
.
mi
==
ffi
.
relModelInfo
{
if
jt
.
fi
.
mi
==
ffi
.
relModelInfo
{
...
...
orm/models_test.go
浏览文件 @
906637ae
...
@@ -332,6 +332,24 @@ func NewComment() *Comment {
...
@@ -332,6 +332,24 @@ func NewComment() *Comment {
return
obj
return
obj
}
}
type
Group
struct
{
GID
string
`orm:"pk;column(gid);size(32);unique"`
Name
string
Permissions
[]
*
Permission
`orm:"reverse(many)" json:"-"`
}
type
Permission
struct
{
ID
int
`orm:"column(id)"`
Name
string
Groups
[]
*
Group
`orm:"rel(m2m);rel_through(github.com/astaxie/beego/orm.GroupPermissions)"`
}
type
GroupPermissions
struct
{
ID
int
`orm:"column(id)"`
Group
*
Group
`orm:"rel(fk)"`
Permission
*
Permission
`orm:"rel(fk)"`
}
var
DBARGS
=
struct
{
var
DBARGS
=
struct
{
Driver
string
Driver
string
Source
string
Source
string
...
...
orm/orm_test.go
浏览文件 @
906637ae
...
@@ -35,6 +35,19 @@ var (
...
@@ -35,6 +35,19 @@ var (
testDateTime
=
formatDateTime
+
" -0700"
testDateTime
=
formatDateTime
+
" -0700"
)
)
type
argAny
[]
interface
{}
// get interface by index from interface slice
func
(
a
argAny
)
Get
(
i
int
,
args
...
interface
{})
(
r
interface
{})
{
if
i
>=
0
&&
i
<
len
(
a
)
{
r
=
a
[
i
]
}
if
len
(
args
)
>
0
{
r
=
args
[
0
]
}
return
}
func
ValuesCompare
(
is
bool
,
a
interface
{},
args
...
interface
{})
(
ok
bool
,
err
error
)
{
func
ValuesCompare
(
is
bool
,
a
interface
{},
args
...
interface
{})
(
ok
bool
,
err
error
)
{
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
{
return
false
,
fmt
.
Errorf
(
"miss args"
)
return
false
,
fmt
.
Errorf
(
"miss args"
)
...
@@ -171,6 +184,9 @@ func TestSyncDb(t *testing.T) {
...
@@ -171,6 +184,9 @@ func TestSyncDb(t *testing.T) {
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
PostTags
))
RegisterModel
(
new
(
PostTags
))
RegisterModel
(
new
(
Group
))
RegisterModel
(
new
(
Permission
))
RegisterModel
(
new
(
GroupPermissions
))
err
:=
RunSyncdb
(
"default"
,
true
,
false
)
err
:=
RunSyncdb
(
"default"
,
true
,
false
)
throwFail
(
t
,
err
)
throwFail
(
t
,
err
)
...
@@ -187,6 +203,9 @@ func TestRegisterModels(t *testing.T) {
...
@@ -187,6 +203,9 @@ func TestRegisterModels(t *testing.T) {
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
PostTags
))
RegisterModel
(
new
(
PostTags
))
RegisterModel
(
new
(
Group
))
RegisterModel
(
new
(
Permission
))
RegisterModel
(
new
(
GroupPermissions
))
BootStrap
()
BootStrap
()
...
@@ -635,6 +654,45 @@ The program—and web server—godoc processes Go source files to extract docume
...
@@ -635,6 +654,45 @@ The program—and web server—godoc processes Go source files to extract docume
throwFail
(
t
,
err
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
id
>
0
,
true
))
throwFail
(
t
,
AssertIs
(
id
>
0
,
true
))
}
}
permissions
:=
[]
*
Permission
{
{
Name
:
"writePosts"
},
{
Name
:
"readComments"
},
{
Name
:
"readPosts"
},
}
groups
:=
[]
*
Group
{
{
GID
:
"g1"
,
Name
:
"admins"
,
Permissions
:
[]
*
Permission
{
permissions
[
0
],
permissions
[
1
],
permissions
[
2
]},
},
{
GID
:
"g2"
,
Name
:
"users"
,
Permissions
:
[]
*
Permission
{
permissions
[
1
],
permissions
[
2
]},
},
}
for
_
,
permission
:=
range
permissions
{
id
,
err
:=
dORM
.
Insert
(
permission
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
id
>
0
,
true
))
}
for
_
,
group
:=
range
groups
{
id
,
err
:=
dORM
.
Insert
(
group
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
id
>
0
,
true
))
num
:=
len
(
group
.
Permissions
)
if
num
>
0
{
nums
,
err
:=
dORM
.
QueryM2M
(
group
,
"permissions"
)
.
Add
(
group
.
Permissions
)
throwFailNow
(
t
,
err
)
throwFailNow
(
t
,
AssertIs
(
nums
,
num
))
}
}
}
}
func
TestCustomField
(
t
*
testing
.
T
)
{
func
TestCustomField
(
t
*
testing
.
T
)
{
...
@@ -1398,6 +1456,18 @@ func TestQueryRelate(t *testing.T) {
...
@@ -1398,6 +1456,18 @@ func TestQueryRelate(t *testing.T) {
// throwFailNow(t, AssertIs(num, 2))
// throwFailNow(t, AssertIs(num, 2))
}
}
func
TestPkManyRelated
(
t
*
testing
.
T
)
{
permission
:=
&
Permission
{
Name
:
"readPosts"
}
err
:=
dORM
.
Read
(
permission
,
"Name"
)
throwFailNow
(
t
,
err
)
var
groups
[]
*
Group
qs
:=
dORM
.
QueryTable
(
"Group"
)
num
,
err
:=
qs
.
Filter
(
"Permissions__Permission"
,
permission
.
ID
)
.
All
(
&
groups
)
throwFailNow
(
t
,
err
)
throwFailNow
(
t
,
AssertIs
(
num
,
2
))
}
func
TestPrepareInsert
(
t
*
testing
.
T
)
{
func
TestPrepareInsert
(
t
*
testing
.
T
)
{
qs
:=
dORM
.
QueryTable
(
"user"
)
qs
:=
dORM
.
QueryTable
(
"user"
)
i
,
err
:=
qs
.
PrepareInsert
()
i
,
err
:=
qs
.
PrepareInsert
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录