Show comments related to post ID!

I’m trying to link up comments to a the “To Do Data” demo, which I’m using to learn Backendless. I’m wondering how to comments related the ID that is passed through, which is saved as a column, relatedPost in the console?!
I know in Parse, the query was:

 [query whereKey:@"photo" equalTo:self.photo];

I’d like to do the same for Backendless. What do I include?!

  • (void)getAllEntitysAsync
{
 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
 QueryOptions *query = [QueryOptions query];
 BackendlessDataQuery *dataQuery = [BackendlessDataQuery query:nil where:nil query:query];
 Responder *responder = [Responder responder:self selResponseHandler:@selector(responseHandler:) selErrorHandler:@selector(errorHandler:)];
 [backendless.persistenceService find:[Comment class] dataQuery:dataQuery responder:responder];
} 

Are you asking how to load a Comment object that has a specific photo as a relation?

Pretty much! Title in the photo below is the comment the user left and relatedID is the ID of the post/photo!

Screen Shot 2016-02-10 at 6.53.20 PM.png

There is a much better way to express that relation. What you have now is not a relation, but a String column where you store object ID of another object. The way you have it, you should a whereClause:

BackendlessDataQuery *query = [BackendlessDataQuery query];
query.whereClause = [NSString stringWithFormat:@"relatedId = \'%@\'", photoObjectId];
BackendlessCollection *collection = [backendless.persistenceService find:[Comment class] dataQuery:query];

Why don’t you create a “normal” Backendless relation from one table to another?

I would love to but I’m not sure how! Please help!

No problem, it is very easy:

https://backendless.com/feature-11-declaring-relations-between-tables-classes-using-developer-console/

Or you can do it strictly with the APIs without even touching Backendless Console:
https://backendless.com/feature-1-saving-objects-with-relations/

Oh, now… I’m even more confused than I was hahaha. Will the comments be under a column in the post table?

Depending how you structure it. If you open the Post table and create a relation there to the Comments section, then that’s exactly what you are going to get.

Here’s a little video I recorded showing just that:
https://monosnap.com/file/OzE0iEcoB0SNhGmalihW3mqGFb3m2X

You’re the best. That makes sense! How would it be added automatically though? Through the console, it’s manual. The whereclause is working great by the way!

Even if you do not have a table to hold your data, it will be created automatically the first time you try saving an object. Backendless will inspect the object you are saving and create table for it (and tables for any other related object which you reference through the properties). This is what we show in this example: https://backendless.com/feature-1-saving-objects-with-relations/