gen icon indicating copy to clipboard operation
gen copied to clipboard

Add embedded structs on generate

Open darkbanjo opened this issue 2 years ago • 2 comments

I want to generate all models from my database tables, using g.GenerateAllTable()...,, but I'd like for it to add all of the embedded fields too.

For example, with a struct like User:

type Users struct {
	ID             string         `gorm:"column:id;primaryKey" json:"id"`
	EffectiveDate  time.Time      `gorm:"column:effective_date" json:"effective_date"`
	ExpirationDate time.Time      `gorm:"column:expiration_date" json:"expiration_date"`
	DeletedAt      gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
	Email          string         `gorm:"column:email" json:"email"`
	OrganizationID string         `gorm:"column:organization_id" json:"organization_id"`
	Onboarded      bool           `gorm:"column:onboarded" json:"onboarded"`
}

Is there a way to automatically add the Organization field of type Organization without specifically specifying?

Thought it should be explained here here

How can I achieve this without specifying the relationships for each model?

darkbanjo avatar Oct 12 '23 22:10 darkbanjo

I am looking for the same thing

Flo4604 avatar Oct 20 '23 20:10 Flo4604