Including Related Objects

Including related objects.

In some situations, you may want to return multiple types of related objects in one query.

The following sample collection consists of two columns (owner and subtask) with the pointer-referenced Users and todo collections respectively.

Sample database.Sample database.

Sample database.

The subtask _id is referred to the _id of the parameter from the same collection; while the owner _id is refer to the parameters from the Users collection of the same database.

Examples

curl -X GET 
   -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9"
   -d 'include=owner' 
   https://api.appery.io/rest/1/db/collections/todo
When the query is executed with an include parameter for the key holding this pointer, the pointer will be expanded to the object:

{
 "_id":"5523d8d0e4b0feb6b024f2f2",
 "taskName":"Test new code",
 "_createdAt":"2015-04-07 13:17:04.912",
 "_updatedAt":"2015-04-07 14:09:48.573",
 "owner":{
   "_id":"5457822ee4b0c9bce12bd076",
   "username":"Pete",
   "_createdAt":"2014-11-03 13:25:02.468",
   "_updatedAt":"2015-04-07 13:40:19.956",
   "email":"[email protected]"
   },
You can also do multi-level includes using dot notation:

curl -X GET 
   -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" 
   -d 'include=owner.subtask'  
   https://api.appery.io/rest/1/db/collections/todo
You can also execute a query with multiple fields included. Pass a comma-separated list of keys as the include parameter:

curl -X GET 
   -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" 
   -d 'include=owner,subtask' 
  https://api.appery.io/rest/1/db/collections/todo
To update the collection, provide the X-Appery-Session-Token parameter and _id of the referenced collection entry you would like to update.

To delete the pointer-referenced entry from the collection, also provide the X-Appery-Session-Token and _id of the referenced collection entry you would like to delete. The response is empty object.