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:
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 )
original_poster.objectId IN (Select Followers FROM Users WHERE Users.objectId='B74024A0-23D8-E701-FF05-A8CE00C98C00')
Which unfortunately , gives me the Error as :
{
"code": 1017,
"message": "Invalid where clause"
}
Could you give me some References/ Pointers on how to Structure this Query Properly Regards, Pujan Paudel
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.
Regards,
Mark
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 ,
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 ) .
BackendlessUser requestor=Backendless.Data.of(BackendlessUser.class).findById(context.getUserId());
ArrayList<String>relationprops=new ArrayList<String>();
relationprops.add("Followers");
Backendless.Data.of(BackendlessUser.class).loadRelations(requestor,relationprops);
BackendlessUser[]queryResults=(BackendlessUser[])requestor.getProperty("Followers");
List<BackendlessUser>mfollowers=Arrays.asList(queryResults);
List<String>followersId=new ArrayList<String>();
for(BackendlessUser user:mfollowers){
followersId.add(user.getObjectId());
}
String whereClauseAdder=converttoStructuredCSV(followersId);
StringBuilder sb=new StringBuilder("original_poster.objectId IN ");
sb.append(whereClauseAdded);
//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 :
Regards,
Pujan
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):
http://support.backendless.com/public/attachments/b5d6850803635a3288c8ed71f7195d1c.png</img>