Your Question
type BaseModel struct {
ID uint `gorm:"primaryKey`
CreatedAt time.time
UpdatedAt time.time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
type User struct {
BaseModel
Name string `gorm:"index`
}
BaseModel is used in many other models as well. What can I do if I want to use composite index for User.DeletedAt and User.Name? The only solution I came about is not to use BaseModel embedded and use the following directly.
type User struct {
ID uint `gorm:"primaryKey`
CreatedAt time.time
UpdatedAt time.time
DeletedAt gorm.DeletedAt `gorm:"index:idx_users_name_deleted_at"`
Name string `gorm:"index:idx_users_name_deleted_at`
}
Is there a way to add the composite index to User as well as using the embedded BaseModel?
I tried to use db.Migrator().CreateIndex(), but found that CreateIndex() method also needs the gorm tag in the model.
Thank you!
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days
Comment From: patrickdemers6
@jinzhu any insight on this?
Comment From: hasa1K
Is there any progress on this issue?