我正在更新从8.0.5到10.3.2的go-pg,并且在列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.SubItem
err = dbConn.Model(&actual).Column("item").Where("sub_item.id = 2").Select()
So(err, ShouldBeNil)
So(actual, ShouldResemble, expected)我遇到的问题是,在v8中,选择了一个带有联接的item。在v10中,它抛出一个“列‘项’不存在”错误。
正确的做法是什么?
https://stackoverflow.com/questions/64931558
复制相似问题