Skip to content

Commit 359336d

Browse files
committed
Add example and note about unsetting a relation using the ItemHydrator
1 parent 644bd9f commit 359336d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.MD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ $attributes = [
372372
'name' => 'Björn Brala',
373373
'homepage' => 'https://github.com/bbrala',
374374
],
375+
'co-author' => null,
375376
'date' => '2018-12-02 15:26:32',
376377
'content' => 'JSON:API was originally drafted in May 2013 by Yehuda Katz...',
378+
'media' => [],
377379
'tags' => [
378380
1,
379381
15,
@@ -399,6 +401,12 @@ echo json_encode($itemDocument, JSON_PRETTY_PRINT);
399401
"id": "f1a775ef-9407-40ba-93ff-7bd737888dc6"
400402
}
401403
},
404+
"co-author": {
405+
"data": null
406+
},
407+
"media": {
408+
"data": []
409+
},
402410
"tags": {
403411
"data": [{
404412
"type": "tag",
@@ -426,6 +434,7 @@ echo json_encode($itemDocument, JSON_PRETTY_PRINT);
426434

427435
As you can see in this example, relations can be hydrated by id, or by an associative array with an id and more attributes.
428436
If the item is hydrated using an associative array, it will be included in the resulting json unless `setOmitIncluded(true)` is called on the relation.
437+
You can unset a relation by passing `null` for singular relations or an empty array for plural relations.
429438

430439
N.B. Morph relations require a 'type' attribute to be present in the data in order to know which type of item should be created.
431440

0 commit comments

Comments
 (0)