소스 검색

fix: properly re-attach parents when decoding

Sam Jaffe 2 주 전
부모
커밋
a87d01a2f6
2개의 변경된 파일3개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      Todos/Model/Project.swift
  2. 2 0
      Todos/Model/Task.swift

+ 1 - 0
Todos/Model/Project.swift

@@ -39,6 +39,7 @@ final class Project: Codable, Ordered {
     category = try container.decode(String.self, forKey: .category)
     name = try container.decode(String.self, forKey: .name)
     tasks = try container.decode([Task].self, forKey: .tasks)
+    tasks.forEach({ $0.project = self })
   }
 
   func encode(to encoder: any Encoder) throws {

+ 2 - 0
Todos/Model/Task.swift

@@ -136,6 +136,8 @@ final class Task: Codable, Ordered {
     subtasks = try container.decode([SubTask].self, forKey: .subtasks)
     notes = try container.decode(String.self, forKey: .notes)
     status = try container.decode(Status.self, forKey: .status)
+    tags.forEach({ $0.task = self })
+    subtasks.forEach({ $0.task = self })
   }
 
   func encode(to encoder: any Encoder) throws {