修bug
This commit is contained in:
@@ -36,6 +36,9 @@ const (
|
||||
// ListPlansOptions 定义了查询计划时的可选参数
|
||||
type ListPlansOptions struct {
|
||||
PlanType PlanTypeFilter
|
||||
|
||||
// IncludeAssociations 控制是否预加载关联的任务和子计划,以便计算 HasTasks 和 HasSubPlans 字段。
|
||||
IncludeAssociations bool
|
||||
}
|
||||
|
||||
// TaskListOptions 定义了查询任务时的可选参数
|
||||
@@ -154,6 +157,11 @@ func (r *gormPlanRepository) ListPlans(ctx context.Context, opts ListPlansOption
|
||||
query = query.Where("plan_type = ?", models.PlanTypeCustom)
|
||||
}
|
||||
|
||||
// 如果需要包含关联,则进行预加载
|
||||
if opts.IncludeAssociations {
|
||||
query = query.Preload("Tasks").Preload("SubPlans")
|
||||
}
|
||||
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user