@@ -35,38 +35,32 @@ For association configuration, see [Associations](../../representations/associat
3535
3636### Create
3737
38- New records have no ` id ` :
39-
4038``` json
4139{
4240 "invoice" : {
4341 "number" : " INV-001" ,
4442 "items" : [
45- { "description" : " Consulting" },
46- { "description" : " Development" }
43+ { "OP" : " create " , " description" : " Consulting" },
44+ { "OP" : " create " , " description" : " Development" }
4745 ]
4846 }
4947}
5048```
5149
5250### Update
5351
54- Existing records include ` id ` :
55-
5652``` json
5753{
5854 "invoice" : {
5955 "items" : [
60- { "id" : " 5" , "description" : " Updated item" }
56+ { "OP" : " update " , " id" : " 5" , "description" : " Updated item" }
6157 ]
6258 }
6359}
6460```
6561
6662### Delete
6763
68- Include ` id ` and ` OP: "delete" ` :
69-
7064``` json
7165{
7266 "invoice" : {
@@ -87,8 +81,8 @@ Combine operations in one request:
8781{
8882 "invoice" : {
8983 "items" : [
90- { "id" : " 5" , "description" : " Updated" },
91- { "description" : " New item" },
84+ { "OP" : " update " , " id" : " 5" , "description" : " Updated" },
85+ { "OP" : " create " , " description" : " New item" },
9286 { "OP" : " delete" , "id" : " 3" }
9387 ]
9488 }
@@ -104,9 +98,10 @@ Nesting can go to any depth:
10498 "invoice" : {
10599 "items" : [
106100 {
101+ "OP" : " create" ,
107102 "description" : " Consulting" ,
108103 "adjustments" : [
109- { "amount" : " 10.00" }
104+ { "OP" : " create " , " amount" : " 10.00" }
110105 ]
111106 }
112107 ]
@@ -120,18 +115,18 @@ TypeScript payloads use a discriminated union with `OP` as the discriminator:
120115
121116``` typescript
122117interface ItemNestedCreatePayload {
123- OP? : ' create' ;
118+ OP: ' create' ;
124119 description: string ;
125120}
126121
127122interface ItemNestedUpdatePayload {
128- OP? : ' update' ;
123+ OP: ' update' ;
129124 id? : string ;
130125 description? : string ;
131126}
132127
133128interface ItemNestedDeletePayload {
134- OP? : ' delete' ;
129+ OP: ' delete' ;
135130 id: string ;
136131}
137132
@@ -141,7 +136,7 @@ type ItemNestedPayload =
141136 | ItemNestedDeletePayload ;
142137```
143138
144- ` OP ` is optional on all variants. When omitted, the adapter infers the operation: records without ` id ` are created, records with ` id ` are updated .
139+ ` OP ` is the discriminator for the union. The adapter uses it to determine the operation for each nested record .
145140
146141## Single Table Inheritance
147142
0 commit comments