I am trying to do something similar to:
http://support.backendless.com/t/how-to-get-parent-table-details-from-child-table
I must be missing something though. I have a class called Playlist with a column of members (a one to many relation of BackendlessUser). I want to find the Playlist that the currentUser belongs to which is in a “child of” column Playlist.members on the currentUser object. When I try a similar query to the one in topic above, in Swift, I get an error. Can you help me figure out the correct syntax for my query?
http://support.backendless.com/public/temp/8e41345bcb4480da86cab505bc68ed29.png</img>
Query:
http://support.backendless.com/public/temp/01473fec6408434432cbb378ea2b41a6.png</img>
Error:
FAULT = ‘3071’ [Could not perform persistence operation: Unable to retrieve data. Query contains invalid object related properties. ] <Could not perform persistence operation: Unable to retrieve data. Query contains invalid object related properties. >
Hi Chris,
Did I understand you correctly that the Playlist table has a collection of user objects referenced by the “members” column?
Also, please confirm: you’re trying to load a playlist that the current user is a part of by being in the “members” collection.
Regards,
Mark
Yes, the Playlist table has a column named members which is a collection of BackendlessUsers.
And yes, I am trying to load a Playlist in which the current user is a member.
Thanks for helping with this!
Chris
Hi Chris,
You need to initialize your BackendlessDataQuery object with a “whereClause”. The “whereClause” is exactly what it sounds like - just like in SQL, it is used as a mechanism to narrow down the searches. We use the SQL-92 syntax to express the search criteria.
Here’s what the whereClause should look like:
members.objectId ='XXXX-XXXX-XXXXX'
where XXXX-XXXX-XXXXX is objectId of the current user.
Also, since you’re fetching playlists, your need to send the “find” request to the Playlist table:
backendless.persistenceService.of(Playlist.ofClass()).find( query )
Hope this helps.
Regards,
Mark
Awesome! I got everything working now. Thanks for help Mark!!
Chris
Mark - i LOVE backendless so exciting
What if you run a query on a bunch of objects but you want to also access or call their parent users (one to many) with the return data collection? Would you need to run another query?