golang - beego orm 如何使用反射获取匿名字段的功能?

查看:360
本文介绍了golang - beego orm 如何使用反射获取匿名字段的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

问题:
beedb 中有这样的一种功能

type SQLModel struct {
    Id       int       `beedb:"PK" sql:"id"`
    Created  time.Time `sql:"created"`
    Modified time.Time `sql:"modified"`
}
type User struct {
    SQLModel `sql:",inline"`
    Name     string `sql:"name" tname:"fn_group"`
    Auth     int    `sql:"auth"`
}
// the SQL table User has the columns: id, name, auth, created, modified
// They are marshalled and unmarshalled automatically because of the inline keyword

我想请问一下,beego orm里面需要怎样实现这种功能
尝试了rel可是不行

解决方案

自从beego1.6.2开始就支持反射匿名函数,使用方法很简单,如下

from 傅小黑

另外,rel是关联不是组合

这篇关于golang - beego orm 如何使用反射获取匿名字段的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆