Backendless Support
 
Answered

Query Users related table through Java Map

Hello

In the docs it says that if I want to query a user table along with its related table then I will get the object as type of Class T. For example

Event event = (Event) result.getProperty("Event");

Is there a way where I can get the related table as a map instead? Ie get is as follows

Map event = (Map) result.getProperty("Event");

Basically I want to query the relate tables from the user table using Java map not custom class

Thank you

Leave a Comment

Comments (5)

photo
1

Hi.

To get your data as a Map use this approach:

List<Map> objects = Backendless.Data.of( "<table_name_as_string>" ).find();

or for relation:

DataQueryBuilder queryBuilder = DataQueryBuilder.create();

queryBuilder.addRelated( "RELATED-PROPERTY-NAME" );

queryBuilder.addRelated( "RELATED-PROPERTY-NAME.RELATION-OF-RELATION" );

List<Map> collection = Backendless.Data.of( "TABLE-NAME" ).find( queryBuilder );

 

Additional information here:

https://backendless.com/docs/android/doc.html#class-to-table-mapping

photo
1

Hello

This method does not work on system tables and this is why I asked the question. If you use Users table it complains that you have to pass backendlessUser. Class

photo
1

Hello,

if you want to get a result as a Map add

  1. Backendless.Data.mapTableToClass("Event", Map.class);

but now Event will be alway a map

photo
1

So do I do this?

  1. Backendless.Data.mapTableToClass("Event", Map.class);
  2. Map event = (Map) result.getProperty("Event");

I am not sure if this is the intended way

photo
1

Yes, correct.

Best regards