Skip to content

Inverted Relation Retrieval

Backendless supports a special query syntax for loading a subset of child objects for a specific parent. Consider the following table schemas:

PhoneBook table:

phonebook-table-schema

Contact table:

contact-table-schema

Address table:

address-table-schema

These tables will be used to demonstrate how to query Backendless for conditional related object retrieval.

The general structure of a whereClause query to load a collection of child objects for a specific parent object is:

ParentTableName[ relatedColumnName ].parentColumnName COLUMN-VALUE-CONDITION

Both columns relatedColumnName and parentColumnName must be declared in a table with name of ParentTableName. The relatedColumnName must be a relation column. The table relatedColumnName points to is the table where the objects must be loaded from.  The examples below demonstrate the usage of this syntax:

Find all contacts in a city for a specific phone book

Suppose objectId of the PhoneBook object for which we need to find contacts isXXXX-XXXX-XXXX-XXXX, then the where clause in the query must look as shown below:

PhoneBook[contacts].objectId= 'XXXX-XXXX-XXXX-XXXX' and address.city = 'New York'

The where clause must be URL encoded when submitted in a REST request:

PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20address.city%20%3D%20%27New%20York%27

The final curl command to run the query is:

curl https://xxxx.backendless.app/api/data/Contact?where=PhoneBook%5Bcontacts%5D.objectId%3D%27DC5B7BDD-2AF6-8949-FFB3-56C2093CBC00%27%20and%20address.city%20%3D%20%27New%20York%27

Find all contacts for the specific phone book where the city name contains letter 'a'

Suppose objectId of the PhoneBook object for which we need to find contacts isXXXX-XXXX-XXXX-XXXX, then the where clause in the query must look as shown below:

PhoneBook[contacts].objectId= 'XXXX-XXXX-XXXX-XXXX' and address.city like '%a%'

The where clause must be URL encoded when submitted in a REST request:

PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20address.city%20like%20%27%25a%25%27

The final curl command to run the query is:

curl https://xxxx.backendless.app/api/data/Contact?where=PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20address.city%20like%20%27%25a%25%27

Find all contacts where age is greater than 20 for a specific phone book

Suppose objectId of the PhoneBook object for which we need to find contacts isXXXX-XXXX-XXXX-XXXX, then the where clause in the query must look as shown below:

PhoneBook[contacts].objectId= 'XXXX-XXXX-XXXX-XXXX' and age > 20

The where clause must be URL encoded when submitted in a REST request:

PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%2020

The final curl command to run the query is:

curl https://xxxx.backendless.app/api/data/Contact?where=PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%2020

Find all contacts for a specific phone book where age is within the specified range

Suppose objectId of the PhoneBook object for which we need to find contacts isXXXX-XXXX-XXXX-XXXX, then the where clause in the query must look as shown below:

PhoneBook[contacts].objectId= 'XXXX-XXXX-XXXX-XXXX' and age >= 21 and age <= 30

The where clause must be URL encoded when submitted in a REST request:

PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%3D%2021%20and%20age%20%3C%3D%2030

The final curl command to run the query is:

curl https://xxxx.backendless.app/api/data/Contact?where=PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%3D%2021%20and%20age%20%3C%3D%2030

Find all contacts for a specific phone book where age is greater than 20 and the city is Tokyo

Suppose objectId of the PhoneBook object for which we need to find contacts isXXXX-XXXX-XXXX-XXXX, then the where clause in the query must look as shown below:

PhoneBook[contacts].objectId= 'XXXX-XXXX-XXXX-XXXX' and age > 21 and address.city = 'Tokyo'

The where clause must be URL encoded when submitted in a REST request:

PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%2021%20and%20address.city%20%3D%20%27Tokyo%27

The final curl command to run the query is:

curl https://xxxx.backendless.app/api/data/Contact?where=PhoneBook%5Bcontacts%5D.objectId%3D%20%27XXXX-XXXX-XXXX-XXXX%27%20and%20age%20%3E%2021%20and%20address.city%20%3D%20%27Tokyo%27