Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Cannot do a comparison query for type: PFRelation' Swift

I am trying to query for all of the existing users in my app that the user has not added as a "Friend". I am getting the error

Cannot do a comparison query for type: PFRelation

Here is my current code:

 override func queryForTable() -> PFQuery {

    let currentFriends : PFRelation = PFUser.currentUser()!.relationForKey("friends")

    // Start the query object
    let query = PFQuery(className: "_User")
    query.whereKey("username", notEqualTo: currentFriends)

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

    // Order the results
    query.orderByAscending("username")

    // Return the qwuery object
    return query
}

How do I solve this issue? Thanks

like image 350
Trip Phillips Avatar asked Nov 09 '15 02:11

Trip Phillips


Video Answer


1 Answers

I solved my problem.... in a way. I was unable to compare the PFRelation so I created a helper Parse class that saves the user who adds the other user as "from" and the user they add as "to" then I am able to compare them like this.

let currentUser = PFUser.currentUser()?.username

    let currentFriends = PFQuery(className: "Friends")
    currentFriends.whereKey("from", equalTo: currentUser!)

    // Start the query object
    let query = PFQuery(className: "_User")
    query.whereKey("username", doesNotMatchKey: "to", inQuery: currentFriends)

I hope this helps someone in the future.

like image 192
Trip Phillips Avatar answered Sep 28 '22 03:09

Trip Phillips