亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

最新 go-pg 中的專欄

最新 go-pg 中的專欄

Go
慕碼人2483693 2022-07-11 17:37:39
我正在從 go-pg from 8.0.5to更新10.3.2,我的 ORM 列有問題結構:type Item struct {    ID   int    `pg:"id,pk"`    Name string `pg:"name"`    Desc string `pg:"description"`    SubItems []SubItem `pg:"rel:has-many"`}type SubItem struct {    ID     int    `pg:"id,pk"`    ItemID int    `pg:"item_id"`    Name   string `pg:"name"`    Item Item `pg:"rel:has-one"`}這是單元測試失敗的部分list := []test.Item{{ID: 1, Name: "first"}, {ID: 2, Name: "second"}, {ID: 3, Name: "third"}}subItems := []test.SubItem{{ID: 1, ItemID: 1}, {ID: 2, ItemID: 3}}_, err := dbConn.model(list).Insert()So(err, ShouldBeNil)_, err = dbConn.model(subItems).Insert()So(err, ShouldBeNil)expected := test.SubItem{    ID:     2,    ItemID: 3,    Item:   test.Item{ID: 3, Name: "third"},}var actual test.SubItemerr = dbConn.Model(&actual).Column("item").Where("sub_item.id = 2").Select()So(err, ShouldBeNil)So(actual, ShouldResemble, expected)我遇到的問題是,在 v8 中,這item是通過連接選擇的。在 v10 中,它會拋出“列 'item' 不存在”錯誤。這樣做的正確方法是什么?
查看完整描述

1 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

它在 v9 中進行了更改,請在此處檢查更改:


Query.Column 不再接受關系名稱。使用 Query.Relation 代替,如果關系不存在則返回錯誤。


嘗試使用Relation ,然后您將獲得所有 Item 列。


err = dbConn.Model(&actual).

    Column("_").

    Relation("Item").

    Where("sub_item.id = 2").

    Select()


查看完整回答
反對 回復 2022-07-11
  • 1 回答
  • 0 關注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號