forked from go-gorm/playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
19 lines (17 loc) · 786 Bytes
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main
// User has one `Account` (has one), many `Pets` (has many) and `Toys` (has many - polymorphic)
// He works in a Company (belongs to), he has a Manager (belongs to - single-table), and also managed a Team (has many - single-table)
// He speaks many languages (many to many) and has many friends (many to many - single-table)
// His pet also has one Toy (has one - polymorphic)
type User struct {
ID *int `gorm:"primarykey"`
Name string
CompanyID *int
Languages []Language `gorm:"many2many:UserSpeak;ForeignKey:ID;References:Code,CompanyID;joinForeignKey:user_id;JoinReferences:code,company_id;"`
}
type Language struct {
ID *int `gorm:"primarykey"`
Code int `gorm:"index:idx_lan"`
CompanyID *int `gorm:"index:idx_lan"`
Name string
}