type Order struct {
ID int `json:"id,omitempty"`
Subtotal float64 `json:"subtotal,string" pg:"type:'decimal(18,2)'"`
Customer Customer `json:"customer" pg:"fk:customer_id,rel:has-one"`
CustomerID int `json:"-"`
Products []Product `json:"products" pg:"many2many:order_products"`
}
type OrderProduct struct {
Order Order `json:"order" pg:"fk:order_id,on_delete:CASCADE,rel:has-one"`
OrderID int `json:"-"`
Product Product `json:"product" pg:"fk:product_id,rel:has-one"`
ProductID int `json:"-"`
}
OrderProduct is a model in the "order_products" table.
type Product struct {
ID int `json:"id,omitempty"`
Name string `json:"name" pg:",notnull,unique"`
Price float64 `json:"price,string" pg:"type:'decimal(18,2)'"`
}