0

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

Ha.
  • 3,454
  • 21
  • 24
sermilion
  • 185
  • 1
  • 15

1 Answers1

3

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 "Places.events" 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 = iterator.next();
    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.

Mark Piller
  • 1,046
  • 1
  • 7
  • 6
  • What would be eqvevalent of BackendlessCollection places = Backendless.Data.of( Places.class ).find( query ); in iOS? Thanx! – sermilion Mar 12 '15 at 18:07
  • For iOS, see the examples at the bottom of the following chapter in the doc: http://backendless.com/documentation/data/ios/data_relations_retrieve.htm – Mark Piller Mar 12 '15 at 21:53
  • Hey Mark , i need to ask a question. I have same system but i need to put object in android code. I can specify like : I wanna put Places object to my event object using android code. How i can do this – Yasin Kaçmaz Mar 14 '16 at 18:13
  • @YasinKaçmaz, the answer is right in the documentation: https://backendless.com/documentation/data/android/data_relations_save_update.htm – Mark Piller Mar 15 '16 at 05:37