求救Beego大神們,Beego orm 怎麼限制Relation裡返回的Variable?
type Accounts struct {
Id int `orm:"column(account_id);pk"`
UserName string `orm:"column(user_name);null" json:"omitempty"`
Hash string `orm:"column(hash)" json:"omitempty"`
IsLogin bool `orm:"column(is_login)" json:"omitempty"`
ModifiedAt time.Time `orm:"column(modified_at);type(timestamp without time zone)" json:"omitempty"`
CreatedAt time.Time `orm:"column(created_at);type(timestamp without time zone)" json:"omitempty"`
Status *DataStatus `orm:"column(status);rel(fk)"`
Role *AccountRoles `orm:"column(role);rel(fk)"`
}
func GetAccountsById(id int) (v *Accounts, err error) {
o := orm.NewOrm()
v = &Accounts{Id: id}
err = o.QueryTable("accounts").Filter("Id", id).RelatedSel().One(v, "account_id", "hash", "is_login", "status", "role")
if err == nil {
return v, nil
}
return nil, err
}
返回值為
{
"Id": 1,
"Hash": "$2a$13$LVfN1o9BTOCIqDBB/bVzg.3NrYRSHNuLaNp5LoJSg124yaq/xMznK",
"IsLogin": false,
"Status": {
"Id": 1,
"Description": "Account verified with email",
"ModifiedAt": "2018-11-16T21:11:30.900571Z",
"CreatedAt": "2018-11-16T21:11:30.900571Z"
},
"Role": {
"Id": 1,
"Name": "System Administrator",
"ModifiedAt": "2018-11-16T21:11:29.408474Z",
"CreatedAt": "2018-11-16T21:11:29.408474Z"
}
}
理想的狀態為
{
"Id": 1,
"Hash": "$2a$13$LVfN1o9BTOCIqDBB/bVzg.3NrYRSHNuLaNp5LoJSg124yaq/xMznK",
"IsLogin": false,
"Status": {
"Id": 1,
"Description": "Account verified with email"
},
"Role": {
"Id": 1,
"Name": "System Administrator"
}
}
請問 Beego ORM 要怎麼 Filter Relation 裡的 Variable? 類似 o.QueryTable("accounts").Filter("Id", id).RelatedSel().One(v, "account_id", "hash", "is_login", "status.data_status_id", "role.role_id")
更多原創文章乾貨分享,請關注公眾號
- 加微信實戰群請加微信(註明:實戰群):gocnio
相關文章
- beego orm使用GoORM
- beego orm中時區的問題GoORM
- beego的ORM-配置資料庫GoORM資料庫
- golang beego orm 查詢條件 or andGolangORM
- beego orm join 聯合查詢的問題GoORM
- beego orm 時間相差八小時GoORM
- Go實戰專案-Beego的orm的基本使用GoORM
- beego ORM 建立模型,生成表。遇到的一些坑。GoORM模型
- 關於Beego ORM和 request body 的對映問題GoORM
- beego的orm針對postgresql的jsonb欄位的查詢GoORMSQLJSON
- beego 怎麼與vue.js一起使用?GoVue.js
- Beego 再出發Go
- beego問題Go
- 建議beego的ORM,可以實現表欄位註釋的新增GoORM
- Beego: 怎麼在 c.ServeJSON() 後馬上停止GoJSON
- beego 什麼時候支援grpcGoRPC
- Beego 框架巔峰之路Go框架
- beego tag詳解Go
- docker建立beego映象DockerGo
- beego訪問redisGoRedis
- beegoapix - beego api extensionGoAPI
- beego & bee 1.9.0 releasedGo
- windows 安裝beegoWindowsGo
- beego中struct中有field是slice型別怎麼儲存?GoStruct型別
- [beego新手入門]基於web框架-beego的RESTful API的構建之旅GoWeb框架RESTAPI
- beego rest ful 請求引數為JSON怎麼獲取GoRESTJSON
- beego 架構(API 版)Go架構API
- Beego Models之二Go
- beego框架程式碼分析Go框架
- beego建立專案流程Go
- beego快取問題Go快取
- beego上傳檔案Go
- beego & bee 1.9.0 releasedGo
- Beego 自動化部署Go
- beego的安裝和升級Go
- 怎麼獲取beego查詢的的結果,Students這個裡面的結果為啥是初始化的?Go
- beego Redirect後會自動訪問/favicon.ico 怎麼取消?Go
- Beego 中容易被我們忽視的問題之 Memory 快取篇Go快取