go-admin icon indicating copy to clipboard operation
go-admin copied to clipboard

[Question] How to use more complex table relations?

Open bgruszka opened this issue 4 years ago • 0 comments

Description [describe your questions]

I have these gorm models defined:

type Product struct {
	ID          uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
	Title       string    `gorm:"not null"`
	Subtitle    string
	Price       decimal.Decimal `gorm:"not null"`
	State       ProductState    `gorm:"not null"`
	UserID      uint            `gorm:"not null;index"`
	User        User
	Details     ProductDetail
	External    ExternalProduct
	Description ProductDescription
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type ProductDetail struct {
	ProductID uuid.UUID `gorm:"type:uuid;primaryKey"`
	Product   *Product
	ColorID   uint8 `gorm:"index"`
	Color     ProductColor
	Genders   []ProductGender `gorm:"many2many:product_details__product_genders;foreignKey:ProductID"`
	SizeID    uint8           `gorm:"index"`
	Size      ProductSize
	BrandID   uint16 `gorm:"index"`
	Brand     ProductBrand
	TypeID    uint16 `gorm:"index"`
	Type      ProductType
}

type ProductBrand struct {
	ID   uint16 `gorm:"primaryKey"`
	Text string `gorm:"unique:true"`
}

and I would like to know how to access and modify brand assigned to specific product in products table. I haven't found any example for it, how to use go-admin with mid-tables like in the example above.

bgruszka avatar Dec 22 '20 14:12 bgruszka