GORM Playground Link
https://github.com/go-gorm/playground/pull/497
Description
When I do many2many relation, sometimes you want to have additional index other than the one created by primary composite key, e.g. I have
type User struct {}
type Organization struct {}
type UserOrganization struct {
UserId string
OrganizationId string
}
by default it create primarily key, e.g. (userId, orgId), but I also want to query by org id, so I need to have an index like:
type UserOrganization struct {
UserId string `gorm:"primaryKey,priority=1;`
OrganizationId string `gorm:"primaryKey,priority=2;index"`
}
but if you do this, from an clean database, it will only create index, not the primary key
the workaround is to just use another composite index, but not really a nice solution
Comment From: a631807682
type UserOrganization struct {
UserId string `gorm:"primaryKey;`
OrganizationId string `gorm:"primaryKey;index"`
}
primaryKey not support priority
Comment From: zfy0701
@a631807682 any particular reason why it can't be supported? we are happy to contribute if it's possible
Comment From: a631807682
@zfy0701 just haven't supported it yet, welcome to contribute it.