简体   繁体   中英

'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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM