Hello,

I have a user model, I want to split it in 10 tables user_0, user_1,...user_9

type User struct {
    Id        uint32    `gorm:"primary_key" json:"id"`
    Name      string    `gorm:"size:64" json:"name"`
    CreatedAt time.Time `json:"created_at"`
    UpdatedAt time.Time `json:"updated_at"`
}

func UserTable(u *User) func(tx *gorm.DB) *gorm.DB {
    return func(tx *gorm.DB) *gorm.DB {
        return tx.Table(fmt.Sprintf("user_%d", u.Id%10))
    }
}

I use Scopes to specify table name for query

  u := &User{Id: 100}
  db.Scopes(UserTable(u)).Create(u)

However I am wondering how to create table with dynamic names? I want to create table user_0, user_1,...user_9 together, not to change TableName() each time, is there any elegant way?

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: leafney

How to solve the same need? So why closed?

Comment From: stonecool

You can specify the table name before the operation db.Table("table_name")