Documentation ¶
Index ¶
- func CreateUser2(db *gorm.DB)
- func FindUserPreloadOrders(db *gorm.DB)
- type Address
- type Cat
- type Company
- type CreditCard
- type CreditCardM
- type Dog
- type DogM
- type Language
- type LanguageOverrideForeignKey
- type LanguagesBackReference
- type Order
- type Person
- type PersonAddress
- type Toy
- type ToyM
- type User
- type User2
- type User2OverrideForeignKey
- type User3
- type UserBackReference
- type UserForeignKeyConstrains
- type UserForeignKeyConstraints
- type UserM
- type UserMOverrideForeignKey
- type UserMOverrideReferences
- type UserMSelfReferentialHasMany
- type UserModel
- type UserModelOverrideForeignKey
- type UserModelOverrideReferences
- type UserOverrideForeignKey
- type UserOverrideReferences
- type UserSelfReferentialHasOne
- type UserSelfReferentialMany2Many
- type UserSpecifyReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateUser2 ¶
func FindUserPreloadOrders ¶
Types ¶
type CreditCard ¶
CreditCard belongs to UserModel, UserID is the foreign key
type CreditCardM ¶
type LanguagesBackReference ¶
type LanguagesBackReference struct { gorm.Model Name string Users []*UserBackReference `gorm:"many2many:user_languages;"` }
type PersonAddress ¶
type PersonAddress struct { PersonID uint `gorm:"primaryKey"` AddressID uint `gorm:"primaryKey"` CreatedAt time.Time DeletedAt gorm.DeletedAt }
func RetrieveJoinTables ¶
func RetrieveJoinTables(db *gorm.DB) ([]PersonAddress, error)
type User ¶
User belongs to Company, CompanyID is the foreign key. There is both a CompanyID and a Company. By default, the CompanyID is implicitly used to create a foreign key relationship between the User and Company tables, and thus must be included in the User struct in order to fill the Company inner struct.
type User2 ¶
type User2 struct { gorm.Model Name string Languages []Language `gorm:"many2many:user_languages;"` }
User2 has and belongs to many languages, `user_languages` is the join table When using GORM AutoMigrate to create a table for User, GORM will create the join table automatically.
type User2OverrideForeignKey ¶
type User2OverrideForeignKey struct { gorm.Model Languages []LanguageOverrideForeignKey `gorm:"many2many:user_languages;foreignKey:Refer;joinForeignKey:UserReferID;references:Refer;joinReferences:ProfileReferID"` Refer uint `gorm:"index:;unique"` }
type UserBackReference ¶
type UserBackReference struct { gorm.Model Languages []*LanguagesBackReference `gorm:"many2many:user_languages;"` }
type UserForeignKeyConstrains ¶
type UserForeignKeyConstrains struct { gorm.Model CreditCard CreditCard `gorm:"constrains:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
type UserM ¶
type UserM struct { gorm.Model CreditCards []CreditCard }
UserM has many CreditCards, UserID is the foreign key
type UserMOverrideForeignKey ¶
type UserMOverrideForeignKey struct { gorm.Model // CreditCardM.UserRefer = User.ID CreditCards []CreditCardM `gorm:"foreignKey:UserRefer"` }
type UserMOverrideReferences ¶
type UserMOverrideReferences struct { gorm.Model MemberNumber string // CreditCard.UserNumber = User.MemberNumber CreditCards []CreditCardM `gorm:"foreignKey:UserNumber;references=MemberNumber"` }
type UserMSelfReferentialHasMany ¶
type UserMSelfReferentialHasMany struct { gorm.Model Name string ManagerID *uint Teammates []UserMSelfReferentialHasMany `gorm:"foreignKey:ManagerID"` }
type UserModel ¶
type UserModel struct { gorm.Model CreditCard CreditCard }
UserModel has one CreditCard, UserID is the foreign key
type UserModelOverrideForeignKey ¶
type UserModelOverrideForeignKey struct { gorm.Model CreditCard CreditCard `gorm:"foreignKey:UserName"` }
UserModelOverrideForeignKey For a has one relationship, a foreign key field must also exist, the owner will save the primary key of the model belongs to it into this field.
type UserModelOverrideReferences ¶
type UserModelOverrideReferences struct { gorm.Model Name string `gorm:"index"` CreditCard CreditCard `gorm:"foreignKey:UserName;references:name"` }
UserModelOverrideReferences When save User model, save User.name to CreditCard.UserName as to set up the foreign key. By default, the owned entity will save the has one model's primary key into a foreign key.
type UserOverrideForeignKey ¶
type UserOverrideReferences ¶
type UserSelfReferentialHasOne ¶
type UserSelfReferentialHasOne struct { gorm.Model Name string ManagerID *uint Manager *UserSelfReferentialHasOne }
type UserSpecifyReference ¶
type UserSpecifyReference struct { gorm.Model Name string CompanyID string // Company already exists CompanyID field, we need to specify the references field // to keep association to be `belongs to`, otherwise, GORM will guess it as `has one` Company Company `gorm:"references:CompanyID"` }
UserSpecifyReference GORM usually guess the relationship as `has one` if override foreign key name already exists in owner's type, we need to specify references in the belongs to relationship.