Hi, I’m trying to retrieve a relationship data but I don’t know why I can’t. I have the table Comment where I did the relationship (one to many) and I have my table beach where I can get the comments. In table beach I have this column Comment.beachId that is the column name that I’m trying retrieve, and in table Comment I have the column beachId.
When I try to retrieve the data I always get null in the private String Comment; I supossed that maybe something with this could be wrong…
This is the main table domain: (have his getter/setter)
private String city;
private String country;
private String name;
private String description;
private GeoPoint location;
private String Comment;
private String distance;
private String duration;
This is my comment domain:
private String message;
private String authorEmail;
This is the method:
String whereClause = "distance( " + currentLatitudeWithDot + ", " + currentLongitudeWithDot + “, location.latitude, location.longitude ) < km(100)”;
BackendlessDataQuery dataQuery = new BackendlessDataQuery(whereClause);
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated(“location”);
queryOptions.addRelated(“Comment.beachId”);
dataQuery.setQueryOptions(queryOptions);
Backendless.Data.of(Beach.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Beach>>() {
@Override
public void handleResponse(final BackendlessCollection<Beach> response) {
.
.
.
}
I have another question that have relationship with this question. If I can retrieve the information of this relationship, I have all the columns of the table that I do the relationship??
Thanks
Sorry but I can’t edit my own question. I did some changes, please get this updated text as reference:
Hi, I’m trying to retrieve a relationship data but I don’t know why I can’t. I’ve added a couple of screenshot to see it better. Basicatly my problem is… if I don’t enable ‘autoload’ I can’t get any data. I only can retrieve data if I enable the ‘autoload’ button, but I always get empty the string comment that I have in my class.
That i want to get is all the comment object for every object of my domain Beach
This is the main table domain: (have his getter/setter)
private String city;
private String country;
private String name;
private String description;
private GeoPoint location;
private String comment;
private String distance;
private String duration;
This is my comment domain:
private String message;
private String authorEmail;
This is the method with the queryOptions comment:
String whereClause = "distance( " + currentLatitudeWithDot + ", " + currentLongitudeWithDot + “, location.latitude, location.longitude ) < km(100)”;
BackendlessDataQuery dataQuery = new BackendlessDataQuery(whereClause);
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated(“location”);
//queryOptions.addRelated(“comment”);
dataQuery.setQueryOptions(queryOptions);
Backendless.Data.of(Beach.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Beach>>() {
@Override
public void handleResponse(final BackendlessCollection<Beach> response) {
.
.
.
}
Another question, what’s the correct way to do the relationship, like I have before or like that have in the comment?
Thanks
Hi Salva,
In your example, you’re trying to load the “location” relation, and it should be available in the response. If you want to also retrieve “comment” relation, just uncomment the following line:
queryOptions.addRelated("comment");
Basically, what you’re trying to do is described in the documentation here: https://backendless.com/documentation/data/android/data_relations_retrieve.htm (under the Single Step Retrieval title)
If the example from the docs doesn’t work, please feel free to report it.
Hi Sergey,
The problem is if I uncomment the
queryOptions.addRelated("comment");
I can’t get any data. Don’t work
Yes, I want to get the two relations, ‘location’ and ‘comment’. In the Beach class domain I have to have a string comment, as well?
Could you try also omit the where clause temporarily and check if that will return any data?
IHi Sergey, If I omit where clause with queryOptions.addRelated(“comment”) enable. I can’t get any data.
I only can get the retrieve data when I omit
queryOptions.addRelated("comment");
I thought that something is wrong whit this queryOptions but aparently I’m doing the same that the documentation said…
I attach you the debug with both queryoptions enable
I’m thinking about this… could be probably that something is wrong in the domain class in my project??
I’ve just found the answer… My error was in my java domain class. You have to refer to your relation table like this:
private List<OrderItem> items;
I found the information in this link: https://backendless.com/how-to-load-relational-data-from-mbaas/