Last active
June 20, 2021 16:22
-
-
Save mozarik/05206f38915f4951f931b77dea8b901b to your computer and use it in GitHub Desktop.
Example of Models in GORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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