Skip to end of metadata
Go to start of metadata

Relational Fields provide a simple way for users to define relations between any Mobile Backend Services (MBS) objects.

Create a relational field

To add or update a relation, you must provide an MBS object ID and an MBS object type. These values together identify a unique MBS object. The relation is specified using one of these formats:

Where TYPENAME indicates MBS type or MBS custom object type of the object pointed to. For example, ArrowDB_User represents an MBS User object, ArrowDB_Photo represents an MBS Photo object, and CUSTOM_car represents an MBS custom object of class car.

To create the relation, create a custom field using one of the relational field name formats shown above. For example, in the following custom fields, we add two relations:

For example, when creating a custom car object, we can specify an owner and picture for the car:

 Expand source

Show a relational field

When you show an MBS object, if the MBS object has a relation to another MBS object, MBS includes the referenced Mobile Backend Services object. For example, suppose a Custom object of type car has two relations: an owner and a picture. When you call show on the object, the user and photo object are included in the response. Example JSON response:

 Expand source

Query a relational field

A relation points to an Mobile Backend Services object, so to query a relation, you must first get the Mobile Backend Services object pointed by the relation. For example, if you want to query cars whose owner is “John Smith”, you first need to find the {@link Users} object whose full name is “John Smith”:

If the user exists, use the user ID to query the custom objects collection for cars that have a [ACS_User]owner_id property with the specified value.

Remove a relational field

To remove a relational field from an Mobile Backend Services object, set the field's value to null. For example, remove to picture from a Custom object: