Advertisement
rhuanpk

Preload in non related tables (GORM)

Jul 10th, 2023 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.04 KB | Source Code | 0 0
  1. type Account struct {
  2.     ID        *uint           `gorm:"primaryKey"`
  3.     UserID    *uint           `gorm:"not null"`
  4.     Name      *string         `gorm:"not null"`
  5.     Balance   *float64        `gorm:"not null"`
  6.     CreatedAt *time.Time      `gorm:"autoCreateTime"`
  7.     UpdatedAt *time.Time      `gorm:"autoUpdateTime"`
  8.     DeletedAt *gorm.DeletedAt `gorm:"index"`
  9.     Finance   *[]Finance
  10. }
  11.  
  12. type Transaction struct {
  13.     ID            *uint           `gorm:"primaryKey"`
  14.     UserID        *uint           `gorm:"not null"`
  15.     EmitterID     *uint           `gorm:"not null"`
  16.     BeneficiaryID *uint           `gorm:"not null"`
  17.     Value         *float64        `gorm:"not null"`
  18.     CreatedAt     *time.Time      `gorm:"autoCreateTime"`
  19.     UpdatedAt     *time.Time      `gorm:"autoUpdateTime"`
  20.     DeletedAt     *gorm.DeletedAt `gorm:"index"`
  21.     Emitter       *Account        `gorm:"foreignKey:EmitterID"`
  22.     Beneficiary   *Account        `gorm:"foreignKey:BeneficiaryID"`
  23. }
  24.  
  25. // var transactions []*Transaction
  26. // *gorm.DB.Preload("Emitter").Preload("Beneficiary").Find(&transactions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement