sermilion sermilion -4 years ago 214
Android Question

Getting parent element form backendless relations

I have table Places in Backendless, that has field Events (relationship with another table). Events table has field Places that has relationship with Places table. So, I want to get Place form Event object. When I try to load Events object, it does not load Place field. So how do I do it? I have attached images to make it more clear what I mean)
enter image description here
enter image description here

Answer Source

The relationship you have is really uni-directional. It may be confusing by looking at the console, but the relationship goes from Places to Events. Notice when the console renders the Events table, it says the "" is a "child of" relationship. This is for reference only and is NOT a part of the Events schema.

Nevertheless, it is possible to load a related Place object given a related Events object. This can be done using a query-based search. Here's a sample code in Java (the syntax of the query is going to be the same regardless of the language you use):

BackendlessDataQuery query = new BackendlessDataQuery();
query.setWhereClause( "events.objectId = 'C4C02F1A-38B3-63F2-FFEB-41C02EF25700'" );
BackendlessCollection<Places> places = Backendless.Data.of( Places.class ).find( query );

Iterator<Places> iterator = places.getCurrentPage().iterator();

while( iterator.hasNext() )
    Places p =;
    System.out.println( p.objectId );

Notice the query is this: "events.objectId = 'C4C02F1A-38B3-63F2-FFEB-41C02EF25700'", where the referenced object ID is one of the Event object. Since the request is executed against the Places table, the query literally means - "find all Places objects where the related "events.objectId" is the specified value".

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download