Fetch objects on the basis of value in relation in where clause

Helllo Backendless
I am trying to fetch the data from a table ‘PartnerRequests’ by where clause on related user object but it is showing error
FAULT = ‘1017’ [Invalid where clause: Unknown column 'where clause] <Invalid where clause: Unknown column 'where clause>
here is my code
QueryOptions *queryOptions = [QueryOptions query];
queryOptions.relationsDepth = @1;
BackendlessDataQuery *query = [BackendlessDataQuery query];
query.queryOptions=queryOptions;
query.whereClause = [NSString stringWithFormat:@“senderUser = ‘%@’”,CURRENT_USER];
// also tried query.whereClause = [NSString
stringWithFormat:@“PartnerRequests[senderUser].objectId =
‘%@’”,[[CURRENT_USER.objectId componentsSeparatedByString:@"."]
objectAtIndex:0]];
[backendless.persistenceService find:[PartnerRequests class] dataQuery:query response:^(BackendlessCollection *collection) {
} error:^(Fault *error) {
NSLog(@"%@",error);
errorBlock(error);
}];
Please guide

here CURRENT_USER is backendless.userService.currentUser

Consider PartnerRequests.parent is BackebdlessUser 1:1 relation. Then your query.whereClause have to be:

 query.whereClause = [NSString stringWithFormat:@"partner.objectId = '%@'", backendless.userService.currentUser.objectId];

You should investigate the docs:

Thanks for your answer, I realized my mistake later, so corrected and its working fine.

Thanks

Hi
Where did you learn about all the notations lile , @‘’, ‘%@’ etc ?

Much thanks in advance

See the documentation:

Actually the problem I am having is, suppose I am making an API service, and the API takes a parameter, which I want to use in my where clause
In all the examples, the where clause check against a literal value rather than a variable
Looking at the conversation here I thought there is a notation I can use by which I specify an outside variable like an API parameter. Please let me know if you can help with that

In this case you need to compose the where clause dynamically.

Thanks for the revealation. Do you mind elaborating further on how and where we make these “dynamic” queries?

Is it for codeless?

Hi Mark
Sorry I was a rude person to you. I am looking around and seeing that you are a helpful person and I should not behave like that :).

I am using codeless, true. This term was unfamiliar to me, but that’s indeed what I am using
BTW I found my answer in this video: https://www.youtube.com/watch?v=KTCMWHI7A5E so no longer have that problem

I have a different problem. I recklessly imported a huge table and want now to pare the records. Is there an SQL console by which I can run a delet query and trim up the table?

While I am here, one more question. When I import a CSV file, all fields default to string, and then it results in an error, something to the effect of “table is too big”. Then when I adjust the datatypes to INT it gets accommodated. The CSV file has quotes around strings and none around numbers. Shouldn’t this result in the types defaulting to INT? I happen to have really wide tables and it is a chore to change the types of 50+ columns. Is there a better way?

Hello Sunil Kidambi,

I have a different problem. I recklessly imported a huge table and want now to pare the records. Is there an SQL console by which I can run a delet query and trim up the table?

Yes, you can use the REST Console — in this screenshot I’ve marked where you can find it:

While I am here, one more question. When I import a CSV file, all fields default to string, and then it results in an error, something to the effect of “table is too big”. Then when I adjust the datatypes to INT it gets accommodated. The CSV file has quotes around strings and none around numbers. Shouldn’t this result in the types defaulting to INT? I happen to have really wide tables and it is a chore to change the types of 50+ columns. Is there a better way?

Unfortunately, there’s no other way to do it directly at the moment.

Regards,
Alexander