fix: tenant apply gorm panic

This commit is contained in:
2025-12-25 11:20:56 +08:00
parent 03117b827b
commit c010710b32

View File

@@ -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
}