0

I am trying to retrieve the the current user's friends by accessing the "friends" column in Parse. The way I set the friends up is by having the user select users in another view that are then added to a Relation called "friends" in their User row in Parse. I can get the users to save as a Relation in Parse but I can't figure out how to actually get those Relationed Users to show up in the Friends Table View. Here is my current code:

 override func queryForTable() -> PFQuery {

    let currentuser = PFUser.currentUser()

    // Start the query object
    let query = PFQuery(className: "_User")


    // Add a where clause if there is a search criteria
    if FriendSearch.text != "" {
        query.whereKey("username", containsString: FriendSearch.text)
    }

    // Order the results
    query.orderByDescending("score")

    // Return the query object
    return query
}

How do I get the current user's related users to appear in the PFTable View Controller? Thanks

2 Answers 2

1

You don't create a new query (particularly using the private class name for users). Instead you get the relation from the user and ask the relation for its query. Once you have that you can add additional parameters to it and return it.

Sign up to request clarification or add additional context in comments.

3 Comments

How do you ask for the User's relation?
- (PFRelation *)relationForKey:(NSString *)key
I am still very confused on how to apply that to my code. I have tried doing "query.whereKey("friends"equalTo: currentuser), but that doesn't work.
0

I figured out what I did wrong. I needed to make a value for the relation in the current user, then make that a query.

// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {

    **let currentuser = PFUser.currentUser()?.relationForKey("friends")

    // Start the query object
    let query = currentuser?.query()**


    // Add a where clause if there is a search criteria
    if FriendSearch.text != "" {

        query!.whereKey("username", containsString: FriendSearch.text)
    }

    // Order the results
    query!.orderByDescending("score")

    // Return the qwuery object
    return query!
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.