Nirav Dangi
Nirav Dangi

Reputation: 3647

Get data from multiple table in single query using Parse

I am using Parse cloud as a backend in my app. Following are the tables in Parse,

- Users

objectId      name
    1         John
    2         Mick
    3         Nirav


- UserConnection

objectId  senderObjectId  receiverObjectId  connectionType
    1         3                  1            connected
    2         2                  1            deleted
    3         2                  3            accepted

(e.g : Here in UserConnection table at objectId 2, the connection between Mick and John is deleted)

Now my query is that, How to fetch user list along with the connectionType for the particular user ?
For example if the user Mick fetches the user list from Users table, result should be,

name    connectionType
John      deleted
Nirav     accepted

How to retrieve data from both Users and UserConnection in a single query using Parse?

Upvotes: 0

Views: 989

Answers (1)

user1555112
user1555112

Reputation: 1987

For what programming language you are asking? I can give you an example in Swift.

var innerQuery = PFQuery(className: "User")
innerQuery.whereKey("senderObjectId", equalTo:PFUser.currentUser())

var query = PFQuery(className: "UserConnection")

query.includeKey("senderObjectId")
query.whereKey("user", matchesQuery:innerQuery);

query.findObjectsInBackgroundWithBlock...

Let me know if that works for you :) I have also quite many issues about queries and parse...

Upvotes: 0

Related Questions