Retrieving parent's id from child's schema

Hello,

I have the following (find attached) column in the Employee table. How can I retrieve this objectId and access this specific Workplace from the Employee?

Thank you.

Employee.jpg

Hi,

Are you asking how to get objectid of the related Workplace objects for the specific Employee?

Mark

Yes

You can retrieve the related objects using the following API:

https://backendless.com/documentation/data/android/data_relations_retrieve.htm

Each related object would be an instance of the Workplace class (you’d need to define the class). If you declare the “objectId” property in Workplace, then it will have the value you’re looking for.

I’m sorry, but it’s still not clear enough.
In this example, after loading Customer, how can I get the OrderItem?
How do I go “backward” the hierarchy? from Customer to Order and then to OrderItem?

Thank you

First you load all 'Order’s with related ‘OrderItem’ which has specific ‘Customer’ with next code


BackendlessDataQuery query = new BackendlessDataQuery();
query.setWhereClause("customer.objectId='<customer_object_id>'" );
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated( "orderItem" )
query.setQueryOptions( queryOptions );
BackendlessCollection<Order> collection = Backendless.Data.of( Order.class ).find( query );

than you can iterate through ‘collection’ and get OrderItem by calling

OrderItem orderItem = order.getOrderItem()