I know I use this way to sortby some column:
QueryOptions queryOptions = new QueryOptions();
queryOptions.addSortByOption( "name desc" );
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setQueryOptions( queryOptions );
But I need to sortby one column in other table. I have 3 tables, here I called table, table1 and table2. My query is about table1 but in this table has 2 relationship columns, with table2 and table.
I need to sortby one column in table2, like it:
String userId = UserIdStorageFactory.instance().getStorage().get();
String whereClause = "table.columnTable = '"+userId+"'";
QueryOptions queryOptions = new QueryOptions();
queryOptions.addSortByOption( "table2.columnTable asc" );
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause(whereClause);
dataQuery.setQueryOptions(queryOptions)
BackendlessCollection<table1> result = Backendless.Persistence.of(table1.class).find(dataQuery);
But this not works. How can I do it?
Sorting applies only to the table where you load objects from. A workaround is this:
Load objects from table1 first
When you need to load related objects from table2, use the sorting option which references columns from table2 and specified the following whereClause:
table1[relationColumnNameForTable2Objects].objectId = objectIdForTable1Object
Hope this helps.
Regards,
Mark
I didn’t understand. In this case, I will put with the real names of columns and tables, cos I’m not understanding.
String whereClause = "user.objectId = '"+userId+"'";
QueryOptions queryOptions = new QueryOptions();
queryOptions.addSortByOption( "match.Start asc" );
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause(whereClause);
dataQuery.setQueryOptions(queryOptions);
BackendlessCollection<MatchPlayers> result = Backendless.Persistence.of(MatchPlayers.class).find(dataQuery);
This is not what I suggested. There are 2 steps:
- you load objects from table 1 first
then :
- for the object from table 1 if you need to load related objects, you use the same API (with BackendlessDataQuery as you did for table1), but the whereClause must be setup this way:
table1[relationColumnNameForTable2Objects].objectId = objectIdForTable1Object
I tried but I couldn’t yet.
First, I load the table1 using in whereClause one relationship column with table3.
String whereClause = "table3.objectId = '"+userId+"'";
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause(whereClause);
BackendlessCollection<table1> result = Backendless.Persistence.of(table1.class).find(dataQuery);
OK, now I have many results and I need to sort by date. Then, I need use what I loaded but with sortby a column in another table(table2).
The table1 has relationship with table3 and table2.
The column in the table1 that is associated to table2 is match.
I don’t know how to continue and I don’t understand well what you tried to help me.
You have loaded objects from table1. Now for a specific table1 object you need to load related objects from table sorted by some column? Is that correct?
No, not for a specific.
I have many objects loaded and I need to sort by with a column in the table2.
I understand. Sorry, we do not support sorting of related objects - you would need to implement it on the client-side.
Regards,
Mark