You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/usage.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,41 @@ There are three types of `Relationships`: `MetaRelationship`, `ToOneRelationship
151
151
152
152
In addition to identifying resource objects by ID and type, `Relationships` can contain `Meta` or `Links` that follow the same rules as [`Meta`](#jsonapimeta) and [`Links`](#jsonapilinks) elsewhere in the JSON:API Document.
153
153
154
+
Metadata can be specified both in the Relationship Object and in the Resource Identifier Object. You specify the two types of metadata differently. As always, you can use `NoMetadata` to indicate you do not intend the JSON:API relationship to contain metadata.
155
+
156
+
```swift
157
+
// No metadata in the Resource Identifer or the Relationship:
158
+
// {
159
+
// "data" : {
160
+
// "id" : "1234",
161
+
// "type": "people"
162
+
// }
163
+
// }
164
+
let relationship1: ToOneRelationship<Person, NoIdMetadata, NoMetadata, NoLinks>
165
+
166
+
// No metadata in the Resource Identifier but some metadata in the Relationship:
167
+
// {
168
+
// "data" : {
169
+
// "id" : "1234",
170
+
// "type": "people"
171
+
// },
172
+
// "meta": { ... }
173
+
// }
174
+
let relationship2: ToOneRelationship<Person, NoIdMetadata, RelMetadata, NoLinks>
175
+
// ^ assumes `RelMetadata` is a `Codable` struct defined elsewhere
176
+
177
+
// Metadata in the Resource Identifier but not the Relationship:
178
+
// {
179
+
// "data" : {
180
+
// "id" : "1234",
181
+
// "type": "people",
182
+
// "meta": { ... }
183
+
// }
184
+
// }
185
+
let relationship3: ToOneRelationship<Person, CoolMetadata, NoMetadata, NoLinks>
186
+
// ^ assumes `CoolMetadata` is a `Codable` struct defined elsewhere
187
+
```
188
+
154
189
The `MetaRelationship` is special in that it represents a Relationship Object with no `data` (it must contain at least one of `meta` or `links`). The other two relationship types are Relationship Objects with either singular resource linkages (`ToOneRelationship`) or arrays of resource linkages (`ToManyRelationship`).
155
190
156
191
To describe a relationship that may be omitted (i.e. the key is not even present in the JSON object), you make the entire `MetaRelationship`, `ToOneRelationship` or `ToManyRelationship` optional.
0 commit comments