1

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ddpishere
  • 751
  • 1
  • 8
  • 23

1 Answers1

0

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?

Russell
  • 3,099
  • 2
  • 14
  • 18
  • yes that is correct it is the relationship between two users – ddpishere Oct 16 '15 at 19:05
  • So you are trying to query for all of the current user's accepted friends? Wouldn't that data be contained within the `Friends` objects returned from the first query? – Russell Oct 16 '15 at 19:09
  • It is but I need additional data from the PFUser object of the friends – ddpishere Oct 16 '15 at 19:17
  • Could you use `includeKey` on the user pointer so all of the additional data is returned at the same time? – Russell Oct 16 '15 at 19:18
  • Such as `friendsListQuery.includeKey("friendId")` `friendsListQuery.includeKey("user")` – ddpishere Oct 16 '15 at 19:23
  • Would there be a way to filter out User records where my field of checkedInTime was not within the last hr? Which I was planning on adding to the second query – ddpishere Oct 16 '15 at 19:25
  • Yup exactly, and then you will be able to access of the data pointed to by the `friendId` pointer and the `user` pointer. As to the other question, there is no way to apply constraints on attributes that have been included using `includeKey`. That would have to be accomplished using two queries – Russell Oct 16 '15 at 19:27
  • ah thats what I was afraid of...any suggestions on the best way to to add that second query? – ddpishere Oct 16 '15 at 19:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92539/discussion-between-russell-and-ddpishere). – Russell Oct 16 '15 at 19:35