省略不工作。
检索错误:
struct deliveryFood/models.Restaurant 的字段 DeliveryZone 发现无效字段,需要为关系定义外键或需要实现 Valuer/Scanner 接口
type Restaurant struct {
ID uint
Name string `json:"name"`
EmployeeId uint `json:"employee_id"`
Phone string `json:"phone"`
Address string `json:"address"`
ImagesUrl *string `json:"images_url"`
Position string `json:"position"`
WorkDays string `json:"work_days"`
StartWorkTime string `json:"start_work_time"`
EndWorkTime string `json:"end_work_time"`
Blocked bool `json:"blocked"`
DeliveryZone []*DeliveryZone `json:",omitempty"`
}
type DeliveryZone struct {
ID uint `json:"id"`
RestaurantId uint `json:"restaurant_id"`
Zone string `json:"zone"`
Price float32 `sql:"-"`
}
Run Code Online (Sandbox Code Playgroud)
err := GetDB().Omit(clause.Associations).Model(Restaurant{}).Create(map[string]interface{} {
"name": rest.Name,
"EmployeeId": rest.EmployeeId,
"Phone": rest.Phone,
"Address": rest.Address,
"ImagesUrl": rest.ImagesUrl, …Run Code Online (Sandbox Code Playgroud)