明壁幕府忍法帳 > Aptana Index > Home > Mobile Backend Services > Mobile Backend Services Guide > Relational Fields

2019.02.07 Ver.21 (2021.1.13)

Relational Fields

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:

[ACS_<TYPENAME>]<fieldname_id>
[ACS_<TYPENAME>]<fieldname_ids>
[CUSTOM_<TYPENAME>]<fieldname_id>
[CUSTOM_<TYPENAME>]<fieldname_ids>

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 the 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:

Custom_fields = {
    "[ACS_User]owner_id":"4d6e77386f70950c89000001",
    "[CUSTOM_car]mycar_id":"4d51d4186f70952d4c000006"
}

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

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:

Query a relational field

A relation points to a 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”:

$ curl -c cookies.txt -b cookies.txt -X GET --data-urlencode
'where={"first_name":"John","last_name":”Smith”}' --data-urlencode 'order=created_at'

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.

$ curl -c cookies.txt -b cookies.txt -X GET --data-urlencode
'where= {"[ACS_User]owner_id":"the user’s object id"}' --data-urlencode
'order=-purchased_at'

Remove a relational field

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

$ curl -b cookies.txt -c cookies.txt -X PUT --data-urlencode 'fields={“[ACS_Photo]picture_id”:null}'