Answer the question
In order to leave comments, you need to log in
ERROR: column "order" is of type json[] but expression is of type record go gorm what to do?
Please tell me I have a model
type Order struct {
ID uint `gorm:"primaryKey;autoIncrement;unique"json:"id"`
Owner string `json:"owner"`
Status string `gorm:"default:ordered"json:"status"`
Phone int `json:"phone"`
Order []OrderStructure `gorm:"type:json[]"json:"order"`
}
type OrderStructure struct {
ID uint `gorm:"primaryKey;autoIncrement;unique"json:"id"`
Brand string `json:"brand"`
ItemId int `json:"item_id"`
Img string `json:"img"`
ItemTotal int `json:"item_total"`
Price string `json:"price"`
Quantity int `json:"quantity"`
Title string `json:"title"`
Type string `json:"type"`
}
Answer the question
In order to leave comments, you need to log in
Most likely it should be something like this
type Order struct {
ID uint `gorm:"primaryKey;autoIncrement;unique"json:"id"`
Owner string `json:"owner"`
Status string `gorm:"default:ordered"json:"status"`
Phone int `json:"phone"`
Order []OrderProduct `gorm:"foreignKey:OrderId"json:"products"`
}
type OrderProduct struct {
ID uint `gorm:"primaryKey;autoIncrement;unique"json:"id"`
// добавляем это поле, чтобы была связь с таблицей Orders
OrderID uint `json:"-"`
Brand string `json:"brand"`
ItemId int `json:"item_id"`
Img string `json:"img"`
ItemTotal int `json:"item_total"`
Price string `json:"price"`
Quantity int `json:"quantity"`
Title string `json:"title"`
Type string `json:"type"`
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question