Backendless relational data fetch issue

When we try to retrieve relational data from query . The query returns Parent class data but relational data is returned as null. We have make the checkbox selection,and also tried using the Backendless data query api

Hello sir,

I have not received any reply from your side for above mentioned question.Please give me a reply

Manish,

Please provide code which demonstrates how you retrieve the data.

Regards,
Mark

Hello Sir,

Please find the code below

BackendlessDataQuery dataQuery = new BackendlessDataQuery();

QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated("profile");
dataQuery.setQueryOptions(queryOptions);
dataQuery.setPageSize(pageSize);
Backendless.Data.of(Comment.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Comment>>() {
    @Override
    public void handleResponse(BackendlessCollection<Comment> response) {
        System.out.println("+response.getData().get(0).getUserProfile() = " +response.getData().get(0).getProfile());
        System.out.println(" name=="+response.getData().get(0).getAuthorEmail());

    }

    @Override
    public void handleFault(BackendlessFault fault) {

    }
});

}

Please remove the “autoload” checkbox, it is not needed since you already do this in the code:

queryOptions.addRelated(“profile”);

Could you please attach your Comment class here?

Regards,
Mark

Please find the screenshot for Comment class

Thanks, but I was talking about the code for the Comment class.

package com.medma.backendlessproject;

import java.io.Serializable;

public class Comment implements Serializable {
private String message;
private String authorEmail;
private UserProfile userProfile;
private String profile;

public String getProfile() {
    return profile;
}

public void setProfile(String profile) {
    this.profile = profile;
}

public Comment() {
}


public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

public String getAuthorEmail() {
    return authorEmail;
}

public void setAuthorEmail(String authorEmail) {
    this.authorEmail = authorEmail;
}

public UserProfile getUserProfile() {
    return userProfile;
}

public void setUserProfile(UserProfile userProfile) {
    this.userProfile = userProfile;
}

}

The problem is right here:

The “profile” property in your Comment class is a String:

public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}

However, the “profile” column in the Comment table is a relation. You need to change the code in the Comment class so the type of the “profile” property becomes UserProfile, like this:

public UserProfile getProfile() {
return profile;
}
public void setProfile(UserProfile profile) {
this.profile = profile;
}

Also, do this somewhere early on in the app (perhaps right after Backendless.initApp):

Backendless.Data.mapTableToClass( "UserProfile", UserProfile.class )

If you have any other related properties you’re expecting from the server, replicate that line for each class.

Regards,
Mark

Thanx solved the problem But I want to ask a question about

Backendless.Data.mapTableToClass( "UserProfile", UserProfile.class )
what does the above  line refer to and why this line was not mentioned in your Doc

The line provides additional instruction to the client-side SDK so it knows what class to use when related objects from the UserProfile table are returned.

The doc is being updated to include that information.

Ok thanx