Populating nested collections
April 17, 2019 ยท View on GitHub
Clients can populate nested collections in output with the populate
argument. It is a comma-separated list of attribute
names. Nested attributes can be specified using a dot notation.
The example below populates manager and manager.colleague.
GET /rest/users/1?populate=manager,manager.colleague
{
"data": {
"id": "1",
"name": "Anthony",
"manager": {
"id": "3",
"name": "Anna",
"colleague": {
"id": "4",
"name": "David"
}
}
}
}
GraphQL does not need the
populate argument since it natively uses selection
fields.
Write commands do not use the populate argument.
Instead, any models present in either the data or cascade
argument will be populated in output.
Modifying nested collections
Clients can modify nested collections by using a nested data
argument.
The example below will create both the user and its manager.
PUT /rest/users/1
{
"id": "1",
"name": "Anthony",
"manager": {
"id": "3",
"name": "Anna"
}
}
Deleting nested collections
To delete nested collections, specify them using the cascade
argument, as a comma-separated list of nested
collections.
The example below will delete user, user.manager, user.manager.friends and
user.colleague.
DELETE /rest/users/1?cascade=manager,manager.friends,colleague