package models import ( "gorm.io/gorm" ) type Cart struct { gorm.Model UserID uint `gorm:"not null;index" json:"user_id"` Items []CartItem `gorm:"foreignKey:CartID" json:"items,omitempty"` } type CartItem struct { gorm.Model CartID uint `gorm:"not null;index" json:"cart_id"` Cart *Cart `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:CartID" json:"cart,omitempty"` ProductID uint `gorm:"not null;index" json:"product_id"` Product *Product `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:ProductID" json:"product,omitempty"` Quantity int `gorm:"default:1" json:"quantity"` }