我的Go應用程序上有這兩個結構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,所以如果我不必提出兩個請求來獲得客戶,那么這將是非常實用的。我在這里搜索,但找不到一對一關系的示例,有沒有辦法使此查詢不僅獲得客戶數據,還獲得地址?func (u customer) GetCustomers(params string) ([]models.Customer, error) { customers := []models.Customer{} u.db.Preload("Addresses").Find(&customers) return customers, nil}
- 1 回答
- 0 關注
- 98 瀏覽
添加回答
舉報
0/150
提交
取消