
commit 2ac099a37ac7bd74f0a98a6fdc42cc8527404144 Author: Jinzhu <wosmvp@gmail.com> Date: Thu Mar 17 23:49:21 2022 +0800 Refactor #5140 commit 6e3ca2d1aa09943dcfb5d9a4b93bea28212f71be Author: a631807682 <631807682@qq.com> Date: Sun Mar 13 12:52:08 2022 +0800 test: add test for LoadOrStoreVisitMap commit 9d5c68e41000fd15dea124797dd5f2656bf6b304 Author: chenrui <chenrui@jingdaka.com> Date: Thu Mar 10 20:33:47 2022 +0800 chore: add more comment commit bfffefb179c883389b72bef8f04469c0a8418043 Author: chenrui <chenrui@jingdaka.com> Date: Thu Mar 10 20:28:48 2022 +0800 fix: should check values has been saved instead of rel.Name commit e55cdfa4b3fbcf8b80baf009e8ddb2e40d471494 Author: chenrui <chenrui@jingdaka.com> Date: Tue Mar 8 17:48:01 2022 +0800 chore: go lint commit fe4715c5bd4ac28950c97dded9848710d8becb88 Author: chenrui <chenrui@jingdaka.com> Date: Tue Mar 8 17:27:24 2022 +0800 chore: add test comment commit 326862f3f8980482a09d7d1a7f4d1011bb8a7c59 Author: chenrui <chenrui@jingdaka.com> Date: Tue Mar 8 17:22:33 2022 +0800 fix: circular reference save
97 lines
2.0 KiB
Go
97 lines
2.0 KiB
Go
package tests
|
|
|
|
import (
|
|
"database/sql"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 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)
|
|
// NamedPet is a reference to a Named `Pets` (has many)
|
|
type User struct {
|
|
gorm.Model
|
|
Name string
|
|
Age uint
|
|
Birthday *time.Time
|
|
Account Account
|
|
Pets []*Pet
|
|
NamedPet *Pet
|
|
Toys []Toy `gorm:"polymorphic:Owner"`
|
|
CompanyID *int
|
|
Company Company
|
|
ManagerID *uint
|
|
Manager *User
|
|
Team []User `gorm:"foreignkey:ManagerID"`
|
|
Languages []Language `gorm:"many2many:UserSpeak;"`
|
|
Friends []*User `gorm:"many2many:user_friends;"`
|
|
Active bool
|
|
}
|
|
|
|
type Account struct {
|
|
gorm.Model
|
|
UserID sql.NullInt64
|
|
Number string
|
|
}
|
|
|
|
type Pet struct {
|
|
gorm.Model
|
|
UserID *uint
|
|
Name string
|
|
Toy Toy `gorm:"polymorphic:Owner;"`
|
|
}
|
|
|
|
type Toy struct {
|
|
gorm.Model
|
|
Name string
|
|
OwnerID string
|
|
OwnerType string
|
|
}
|
|
|
|
type Company struct {
|
|
ID int
|
|
Name string
|
|
}
|
|
|
|
type Language struct {
|
|
Code string `gorm:"primarykey"`
|
|
Name string
|
|
}
|
|
|
|
type Coupon struct {
|
|
ID int `gorm:"primarykey; size:255"`
|
|
AppliesToProduct []*CouponProduct `gorm:"foreignKey:CouponId;constraint:OnDelete:CASCADE"`
|
|
AmountOff uint32 `gorm:"amount_off"`
|
|
PercentOff float32 `gorm:"percent_off"`
|
|
}
|
|
|
|
type CouponProduct struct {
|
|
CouponId int `gorm:"primarykey;size:255"`
|
|
ProductId string `gorm:"primarykey;size:255"`
|
|
Desc string
|
|
}
|
|
|
|
type Order struct {
|
|
gorm.Model
|
|
Num string
|
|
Coupon *Coupon
|
|
CouponID string
|
|
}
|
|
|
|
type Parent struct {
|
|
gorm.Model
|
|
FavChildID uint
|
|
FavChild *Child
|
|
Children []*Child
|
|
}
|
|
|
|
type Child struct {
|
|
gorm.Model
|
|
Name string
|
|
ParentID *uint
|
|
Parent *Parent
|
|
}
|