Backendless Support

Nested Type Queries involving Data Relations not Working

Hello Backendless ,

I have been Trying to Query Nested Relationships in Backendless , but Somehow I have not been able to Structure the Query Right and get stuck

What I was trying To Do Code Wise is to Run a Backendless Query with Where Clause as:

  1. original_poster.objectId IN ('B74024A0-23D8-E701-FF05-A8CE00C98C00','EC25F4BA-F315-3318-FF53-9389C34E7800')

The Above Query is working perfectly Well , here I have these 'B74024A0-23D8-E701-FF05-A8CE00C98C00','EC25F4BA-F315-3318-FF53-9389C34E7800' Array Loaded Via Relations as data of the Followers Column of Users through Custom Business Logic. But , I want that Query to be replaced by An Inner SQL Query Which Loads the Followers Column and that Can be passed to the left Side of the Query Like : I Tried doing it by using Old School SQL Query (Tested Via REST Console )

  1. original_poster.objectId IN (Select Followers FROM Users WHERE Users.objectId='B74024A0-23D8-E701-FF05-A8CE00C98C00')

Which unfortunately , gives me the Error as :

  1. {
  2. "code": 1017,
  3. "message": "Invalid where clause"
  4. }

Could you give me some References/ Pointers on how to Structure this Query Properly :) Regards, Pujan Paudel

Leave a Comment

Comments (5)


Hi Pujan,

You have to run two separate requests for this. The requests could be combined in an API service so it would be one call from the client side.




Hello Mark ,

Thanks for your reply .

okay , I should be using API Services to achieve this one .

I have read through almost all the docs of API services but couldn't get even the slightest of the hint to get started ( regarding this particular Scenario ) . Probably , did I miss something ? If so , please tell me the part of API service docs that can help me achieve this . If you guys could give a dummy snippet of Code ( too too Minimal ), on reflecting the probable solution of this Scenario , that'd be a very very great part from your side .

as always ,

You Rock Mark

Regards ,


Hi Pujan,

Yes, sounds like you missed the Quick Start guide:




Hello @Mark ,

Okay : I read Through the Quick Start Guide as well as the other docs related to it and well, Unfortunately I am still not Clear on " run two separate requests" and combining to a "Single API " part of it ?

Referencing my Previous Attempt :

I tried to do Something like that Previously ( Not Via Services , but Business Handlers ) by

1)Loading the User based on CodeRunner Context .getUserid() (Along with the relations by using One Step Retrieval Method )

2) Extracting the Object Id's through the Returned List and Reconstructing a Query :

Here's a Snippet of How I achieved that one : But i dont want this to run because I want the inner component to be run Via a Query Itself (that 5s Limit may be crossed while loading a Larger value of Relations is my Worry ) .

  1. BackendlessUser requestor=Backendless.Data.of(BackendlessUser.class).findById(context.getUserId());
  2. ArrayList<String>relationprops=new ArrayList<String>();
  3. relationprops.add("Followers");
  4. Backendless.Data.of(BackendlessUser.class).loadRelations(requestor,relationprops);
  5. BackendlessUser[]queryResults=(BackendlessUser[])requestor.getProperty("Followers");
  6. List<BackendlessUser>mfollowers=Arrays.asList(queryResults);
  7. List<String>followersId=new ArrayList<String>();
  8. for(BackendlessUser user:mfollowers){
  9. followersId.add(user.getObjectId());
  10. }
  11. String whereClauseAdder=converttoStructuredCSV(followersId);
  12. StringBuilder sb=new StringBuilder("original_poster.objectId IN ");
  13. sb.append(whereClauseAdded);
  14. //sb.ToString () will result in a perfectly Working Query

I am Sorry that I didn't get how we could do this with API Services. Hope you can give me a list of instruction regarding this as The Docs is genuinely focusing on a Custom Object type ( a Shopping Cart ) and manipulating components of it alone :




Perhaps this diagram will help you understand how hosted API service can help you accomplish that. The "getData()" method is conceptually the method implemented in the service. The method contains the logic for retrieving data from Backendless (1nd and 2nd calls in the diagram):