gorm/schema/model_test.go

65 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-02-15 19:37:59 +03:00
package schema_test
import (
"database/sql"
"time"
2020-06-02 04:16:07 +03:00
"gorm.io/gorm"
2020-06-02 05:34:50 +03:00
"gorm.io/gorm/utils/tests"
2020-02-15 19:37:59 +03:00
)
type User struct {
*gorm.Model
Name *string
Age *uint
Birthday *time.Time
Account *tests.Account
Pets []*tests.Pet
Toys []*tests.Toy `gorm:"polymorphic:Owner"`
CompanyID *int
Company *tests.Company
2020-02-23 04:38:48 +03:00
ManagerID *uint
2020-02-15 19:37:59 +03:00
Manager *User
Team []*User `gorm:"foreignkey:ManagerID"`
Languages []*tests.Language `gorm:"many2many:UserSpeak"`
Friends []*User `gorm:"many2many:user_friends"`
Active *bool
}
type (
mytime time.Time
myint int
mybool = bool
)
2020-02-15 19:37:59 +03:00
type AdvancedDataTypeUser struct {
ID sql.NullInt64
Name *sql.NullString
Birthday sql.NullTime
RegisteredAt mytime
DeletedAt *mytime
Active mybool
Admin *mybool
}
type BaseModel struct {
ID uint
CreatedAt time.Time
CreatedBy *int
Created *VersionUser `gorm:"foreignKey:CreatedBy"`
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
type VersionModel struct {
BaseModel
Version int
}
type VersionUser struct {
VersionModel
Name string
Age uint
Birthday *time.Time
}