我的Go應(yīng)用程序上有這兩個(gè)結(jié)構(gòu)type Customer struct { ID uint `json: "id" gorm:"primary_key"` Name string `json: "name"` AddressId int `json: "addressId"` Address Address `json: "address"`}type Address struct { ID uint `json: "id" gorm:"primary_key"` ZipCode string `json: "zipCode"` StreetOne string `json: "streetOne"` StreetTwo string `json: "streetTwo"` City string `json: "city"` State string `json: "state"` Number string `json: "number"`}我在我的前端使用Angular,所以如果我不必提出兩個(gè)請(qǐng)求來獲得客戶,那么這將是非常實(shí)用的。我在這里搜索,但找不到一對(duì)一關(guān)系的示例,有沒有辦法使此查詢不僅獲得客戶數(shù)據(jù),還獲得地址?func (u customer) GetCustomers(params string) ([]models.Customer, error) { customers := []models.Customer{} u.db.Preload("Addresses").Find(&customers) return customers, nil}
- 1 回答
- 0 關(guān)注
- 97 瀏覽
添加回答
舉報(bào)
0/150
提交
取消