Set/Add Relation with objects¶
API request must identify the child objects to set/add to the relation explicitly by referencing their IDs.
Set relation -
Add relation -
xxxx.backendless.app is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.
||name of the table where which contains the parent object as identified by
||id of the object for which the relation will be created/set.|
||name of the column which identifies the relation within the parent table (identified as
If the column does not exist in the parent table at the time when the API is called, the value of the "
relationColumnName" argument must include the name of the child table separated by colon and the cardinality notation. The cardinality is expressed as "
:1" for one-to-one relations and "
:n" for one-to-many relations. For example, the value of "
myOrder:Order:1" will create a one-to-one relation column "
myOrder" in the parent table. The column will point to the
Order child table. Likewise, the value of "
myOrder:Order:n" will create a one-to-many relation column "
myOrder" pointing to the
user-token: value-of-the-user-token-header-from-login Content-Type:application/json
||Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the operation will be executed with the security policy associated with the currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless.|
||Must be set to
Must be an array of child object IDs as string values.
[ "childObjectId1", "childObjectId2" ]
Error or number of objects the operation sets for the relation.
The example below sets a relation for a one-to-one column named
address declared in the
Person table. The column must be declared in the table prior to the execution of the request shown below. This necessity is explained by missing table name qualifier in the URL - notice the relation column is
address. If it were specified as
address:Address:1, then the column would be created automatically.
Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.
curl \ -H Content-Type:application/json \ -X POST -d "[ \"XXXXX-XXXXX-XXXXX-XXXXX\" ]" \ https://xxxx.backendless.app/api/data/Person/parentObjectId/address
The following example sets a relation for a one-to-many column named
friends which will be created if missing in the
Person table. The column points to the Users table:
curl \ -H Content-Type:application/json \ -X POST -d "[ \"XXXXX-XXXXX-XXXXX-XXXXX\" ]" \ https://xxxx.backendless.app/api/data/Person/parentObjectId/friends:Users:n
Since the path includes the name of the child table (see the part of the path which included
friends:Users:n), Backendless will create the column if it does not exist. Once created, you can see the column in Backendless console: