Skip to content

Commit

Permalink
Merge pull request #1786 from actiontech/cherry-pick
Browse files Browse the repository at this point in the history
Cherry pick
  • Loading branch information
ColdWaterLW authored Sep 6, 2023
2 parents 42364c0 + 4bb063e commit 7e96299
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/jinzhu/gorm"
)

var UnScopedFunc = func(db *gorm.DB) *gorm.DB { return db.Unscoped() }

type WorkflowTemplate struct {
Model
Name string
Expand Down Expand Up @@ -789,7 +791,7 @@ func (s *Storage) GetWorkflowDetailById(id string) (*Workflow, bool, error) {

func (s *Storage) GetWorkflowExportById(id string) (*Workflow, bool, error) {
w := new(Workflow)
err := s.db.Preload("CreateUser", func(db *gorm.DB) *gorm.DB { return db.Unscoped() }).
err := s.db.Preload("CreateUser", UnScopedFunc).
Preload("Record").Where("id = ?", id).First(&w).Error
if err == gorm.ErrRecordNotFound {
return nil, false, nil
Expand All @@ -803,7 +805,8 @@ func (s *Storage) GetWorkflowExportById(id string) (*Workflow, bool, error) {
}

instanceRecordList := make([]*WorkflowInstanceRecord, 0)
err = s.db.Preload("Instance").Preload("Task").Preload("User").
err = s.db.Preload("Instance", UnScopedFunc).Preload("Task").
Preload("User", UnScopedFunc).
Where("workflow_record_id = ?", w.Record.ID).
Find(&instanceRecordList).Error
if err != nil {
Expand All @@ -821,7 +824,7 @@ func (s *Storage) GetWorkflowExportById(id string) (*Workflow, bool, error) {

steps := make([]*WorkflowStep, 0)
err = s.db.Where("workflow_record_id = ?", w.Record.ID).
Preload("OperationUser").
Preload("OperationUser", UnScopedFunc).
Find(&steps).Error
if err != nil {
return nil, false, errors.New(errors.ConnectStorageError, err)
Expand Down

0 comments on commit 7e96299

Please sign in to comment.