role_menu.go 940 字节
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
}