diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index 304c7d9716..8d6b188f7b 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -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 @@ -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 @@ -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 { @@ -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)