role_menu.go
940 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package models
import (
"github.com/astaxie/beego/orm"
)
type RoleMenu struct {
Id int64 `orm:"column(id);auto" description:"主键"`
RoleId int64 `orm:"column(role_id);null" description:"role.id"`
MenuId int64 `orm:"column(menu_id);null" description:"menu.id"`
Opption string `orm:"column(opption);size(500);null" description:"配置"`
}
func (t *RoleMenu) TableName() string {
return "role_menu"
}
func init() {
orm.RegisterModel(new(RoleMenu))
}
// AddRoleMenu insert a new RoleMenu into database and returns
// last inserted Id on success.
func AddRoleMenu(m *RoleMenu) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
var (
list []RoleMenu
err error
)
o := orm.NewOrm()
_, err = o.QueryTable(&RoleMenu{}).
Filter("role_id", roleid).
All(&list)
if err == orm.ErrNoRows {
return list, nil
}
return list, err
}