Backendless Support
 
Answered

Query Second or Third Level Child

My data model has are more than two levels. How can I include in where clause 2 and third level child objects.

In your documentation about querying related objects, you have an example of related objects: phonebook, contact, and address. The example query is based on the contact object class. How would you write the same query using the phonebook class? Find all Phonebooks where "address.city = 'Smallville'"

StringBuilder whereClause = new StringBuilder();whereClause.append( "PhoneBook[contacts]" );whereClause.append( ".objectId='" ).append( savedPhoneBook.getObjectId() ).append( "'" );whereClause.append( " and " );whereClause.append( "address.city = 'Smallville'" ); BackendlessDataQuery dataQuery = new BackendlessDataQuery();dataQuery.setWhereClause( whereClause.toString() );List<Contact> result;result = Backendless.Persistence.of( Contact.class ).find( dataQuery ).getCurrentPage();

Leave a Comment

Comments (3)

photo
1

Hi Barry,

if you want to find all phonebooks where contact address city is 'Smallville', the where clause should look next way:

  1. contacts.address.city='Smallville'

photo
1

I am getting an error using that syntax. From the console, I am getting "invalid where clause."

photo
1

Cool. It is now working