Skip to content

Instantly share code, notes, and snippets.

@mozarik
Last active June 20, 2021 16:22
Show Gist options
  • Save mozarik/05206f38915f4951f931b77dea8b901b to your computer and use it in GitHub Desktop.
Save mozarik/05206f38915f4951f931b77dea8b901b to your computer and use it in GitHub Desktop.
Example of Models in GORM
package model
import "gorm.io/gorm"
type User struct {
gorm.Model
Username string
Password string
Role string
}
type Merchant struct {
gorm.Model
Product []Product `gorm:"foreignkey:MerchantID;association_foreignkey:ID"`
Outlet []Outlet `gorm:"foreignkey:MerchantID;association_foreignkey:ID"`
UserID User `gorm:"foreignkey:ID;association_foreignkey:ID"`
}
type Product struct {
gorm.Model
Name string
Sku uint
Image string
MerchantID uint
}
type ProductOutlet struct {
gorm.Model
Product []Product `gorm:"foreignkey:MerchantID;association_foreignkey:ID"`
Price uint
OutletID uint
}
type Outlet struct {
gorm.Model
UserID User `gorm:"foreignkey:ID;association_foreignkey:ID"`
Product []ProductOutlet `gorm:"foreignkey:OutletIDassociation_foreignkey:ID"`
MerchantID uint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment