Fetch related data object with DataQuery

I Have two tables, One “Category” with basic property columns and another “BNCImage” with ‘imageURL’ and ‘categoryConnection’ as property columns. When I try to search for the ‘categoryConnection’ with a value in the “BNCImage” to fetch the corresponding ‘imageURL’ property it shows “Fault: invalid where clause”. Below is the code for the data query.

final Future<Category> retrievedCat = new Future<Category>();
retrievedCat.set(cat);


BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause("categoryConnection = " + retrievedCat.get().getObjectId());
Backendless.Data.of(BNCImage.class).find(dataQuery, new LoadingCallback<BackendlessCollection<BNCImage>>(this, getString(R.string.loading_categories), true) {


@Override
public void handleResponse(BackendlessCollection<BNCImage> response) {
try {
Log.i(TAG, response.toString());
retrievedCat.get().setConnectedImage(response.getData().get(0));
adapter.notifyDataSetChanged();
} catch (InterruptedException e) {
e.printStackTrace();
}


super.handleResponse(response);
}


@Override
public void handleFault(BackendlessFault fault) {
super.handleFault(fault);
}
});

Also find attached the activity file.

try this one

dataQuery.setWhereClause("categoryConnection = '" + retrievedCat.get().getObjectId() + "'");

Still getting the same error. “Invalid where clause”

what is your application id ?

68C8EEEA-48AB-4D13-FF7A-444D030CD500
Is it safe to provide this here?

yes, no body can not do any thing with your app with out secret key.

Okay. Thanks!

Ok, now I see the problem. categoryConnection is a relation so your query should be like this

dataQuery.setWhereClause("categoryConnection.objectId = '" + retrievedCat.get().getObjectId() + "'");

Thanks Sergey!

So we can’t fetch whole relation as whole, instead individual properties can be fetched or queried to. Understood!