@@ -86,33 +86,6 @@ extension Person: Entity {
8686 )
8787 ]
8888 }
89-
90- init ( from container: ModelData ) throws {
91- guard container. entity == Self . entityName else {
92- throw DecodingError . typeMismatch ( Self . self, DecodingError . Context ( codingPath: [ ] , debugDescription: " Cannot decode \( String ( describing: Self . self) ) from \( container. entity) " ) )
93- }
94- guard let id = UUID ( uuidString: container. id. rawValue) else {
95- throw DecodingError . dataCorrupted ( DecodingError . Context ( codingPath: [ ] , debugDescription: " Cannot decode identifier from \( container. id) " ) )
96- }
97- self . id = id
98- self . name = try container. decode ( String . self, forKey: Person . CodingKeys. name)
99- self . created = try container. decode ( Date . self, forKey: Person . CodingKeys. created)
100- self . age = try container. decode ( UInt . self, forKey: Person . CodingKeys. age)
101- self . events = try container. decodeRelationship ( [ Event . ID ] . self, forKey: Person . CodingKeys. events)
102- }
103-
104- func encode( ) -> ModelData {
105-
106- var container = ModelData (
107- entity: Self . entityName,
108- id: ObjectID ( rawValue: self . id. description)
109- )
110- container. encode ( self . name, forKey: Person . CodingKeys. name)
111- container. encode ( self . created, forKey: Person . CodingKeys. created)
112- container. encode ( self . age, forKey: Person . CodingKeys. age)
113- container. encodeRelationship ( self . events, forKey: Person . CodingKeys. events)
114- return container
115- }
11689}
11790
11891struct Event : Equatable , Hashable , Codable , Identifiable {
@@ -183,29 +156,4 @@ extension Event: Entity {
183156 inverseRelationship: PropertyKey ( Person . CodingKeys. events) )
184157 ]
185158 }
186-
187- init ( from container: ModelData ) throws {
188- guard container. entity == Self . entityName else {
189- throw DecodingError . typeMismatch ( Self . self, DecodingError . Context ( codingPath: [ ] , debugDescription: " Cannot decode \( String ( describing: Self . self) ) from \( container. entity) " ) )
190- }
191- guard let id = UUID ( uuidString: container. id. rawValue) else {
192- throw DecodingError . dataCorrupted ( DecodingError . Context ( codingPath: [ ] , debugDescription: " Cannot decode identifier from \( container. id) " ) )
193- }
194- self . id = id
195- self . name = try container. decode ( String . self, forKey: Event . CodingKeys. name)
196- self . date = try container. decode ( Date . self, forKey: Event . CodingKeys. date)
197- self . people = try container. decodeRelationship ( [ Person . ID ] . self, forKey: Event . CodingKeys. people)
198- }
199-
200- func encode( ) -> ModelData {
201-
202- var container = ModelData (
203- entity: Self . entityName,
204- id: ObjectID ( rawValue: self . id. description)
205- )
206- container. encode ( self . name, forKey: Event . CodingKeys. name)
207- container. encode ( self . date, forKey: Event . CodingKeys. date)
208- container. encodeRelationship ( self . people, forKey: Event . CodingKeys. people)
209- return container
210- }
211159}
0 commit comments