From 352c9d92463164ae6a374251c5929dca8568ee3d Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 14 Sep 2025 14:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DcreatePlan=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/infra/repository/plan_repository.go | 4 ++-- internal/infra/repository/plan_repository_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/infra/repository/plan_repository.go b/internal/infra/repository/plan_repository.go index c8c544c..3e6a444 100644 --- a/internal/infra/repository/plan_repository.go +++ b/internal/infra/repository/plan_repository.go @@ -137,10 +137,10 @@ func (r *gormPlanRepository) CreatePlan(plan *models.Plan) error { if plan.ContentType == models.PlanContentTypeSubPlans { childIDsToValidate := make(map[uint]bool) for _, subPlanLink := range plan.SubPlans { - if subPlanLink.ChildPlan == nil || subPlanLink.ChildPlan.ID == 0 { + if subPlanLink.ChildPlanID == 0 { return ErrSubPlanIDIsZeroOnCreate } - childIDsToValidate[subPlanLink.ChildPlan.ID] = true + childIDsToValidate[subPlanLink.ChildPlanID] = true } var ids []uint diff --git a/internal/infra/repository/plan_repository_test.go b/internal/infra/repository/plan_repository_test.go index 3055b60..20fd082 100644 --- a/internal/infra/repository/plan_repository_test.go +++ b/internal/infra/repository/plan_repository_test.go @@ -1134,7 +1134,7 @@ func TestPlanRepository_Create(t *testing.T) { Name: "父计划", ContentType: models.PlanContentTypeSubPlans, SubPlans: []models.SubPlan{ - {ChildPlanID: 1, ExecutionOrder: 1, ChildPlan: &models.Plan{Model: gorm.Model{ID: 1}}}, // 关联已存在的子计划1 + {ChildPlanID: 1, ExecutionOrder: 1}, // 关联已存在的子计划1 {ChildPlanID: 2, ExecutionOrder: 2, ChildPlan: &models.Plan{Model: gorm.Model{ID: 2}}}, // 关联已存在的子计划2 }, },