fix: tenant apply gorm panic
This commit is contained in:
@@ -109,9 +109,10 @@ func (ctl *tenantApply) apply(ctx fiber.Ctx, form *dto.TenantApplyForm) (*dto.Te
|
||||
Config: types.JSON([]byte(`{}`)),
|
||||
}
|
||||
|
||||
db := models.Q.Tenant.WithContext(ctx).UnderlyingDB()
|
||||
// NOTE: 使用全新 Session,避免复用 gen.DO 内部带 Model/Statement 的 *gorm.DB 导致 schema 与 dest 不一致而触发 GORM 反射 panic。
|
||||
db := models.Q.Tenant.WithContext(ctx).UnderlyingDB().Session(&gorm.Session{})
|
||||
err = db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Create(tenant).Error; err != nil {
|
||||
if err := tx.Omit("Users").Create(tenant).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user