How to add objects with relations using REST Console

by on May 10, 2015

In another post, we described how to save data objects using REST Console. The same interface allows to save objects with related data – it is strictly a matter of formatting the request body. Consider the following two data table schemas:

Restaurant table schema:

Notice the locations column, which represents a one-to-many relation with the Location table:

To save a new object in the Restaurant table using the REST Console in Backendless Console:

  1. Select the Restaurant table and click on the REST Console.
  2. Enter the following JSON object into the Request body field:
      "name":"Mama Mia Pizzeria",
           "streetAddress":"123 Main St",
           "city":"New York"

    Notice the locations element – it contains an array with one object. The reason for the array is the one-to-many relationship between Restaurant and Location tables. Additionally, the object inside of the “locations” array contains a special property ___class. The property indicates that the object is an “instance” of the Location object and should be placed into the Locations table.

  3. Click the POST button to save the objects. You will see a response similar to the one in the screenshot below: