PFQueryTable using a subquery not returning results in Swift

173 views Asked by At

I have a Swift project using Parse and I am using PFQueryTable to populate a table with prototype cells. Below is my queryForTable section to query the data I am interested in. My primary query is for a class titled "Friends" that has a pointer column titled user that points to the "User" class. Also in "Friends" class is a column titled friendId that also points to "User"

I want to retrieve records in the "Friends" class where my friendId is equal to my current user and the approved flag is true.

Once I have those records I will be retrieving "User" records that have a checkInTime within the last hour or whatever I set. Right now I am just trying to return records that match my first criteria and showing the username from the "User" class in my table.

override func queryForTable() -> PFQuery {
    let friendsListQuery = PFQuery(className: "Friends")
    friendsListQuery.whereKey("friendId", equalTo: PFUser.currentUser()!)
    friendsListQuery.whereKey("approved", equalTo: true)


    let checkInQuery = PFUser.query()
    checkInQuery!.whereKey("objectId", matchesKey: "user", inQuery: friendsListQuery)


    return checkInQuery!

}

Currently the queries are returning no records. Any ideas?

1

There are 1 answers

9
Russell On BEST ANSWER

The issue is here

checkInQuery!.whereKey("objectId", matchesKey: "user", inQuery: friendsListQuery)

the objectId key cannot match against a user pointer.

In terms of a solution that will depend on the structure of your Parse classes. Is the purpose of the "Friends" to represent the relationship between two users?