我正在從 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' 不存在”錯誤。這樣做的正確方法是什么?
最新 go-pg 中的專欄
慕碼人2483693
2022-07-11 17:37:39