1

So I'm trying to get all UserSports that has a user (pointer to User) with the matching facebookId in User from facebookIdList. facebookIdList contains the id:s. But objects has 0 values. Any ideas?

let userQuery = PFQuery(className: "User")
userQuery.whereKey("facebookId", containedIn: facebookIdList)

let query = PFQuery(className: "UserSport")
query.whereKey("user", matchesQuery: userQuery)
query.includeKey("user")

query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
  if error == nil {
    if let userSports = objects as? [UserSport] {      
      print(userSports)
    }
  }
} 
hugocarlmartin
  • 719
  • 1
  • 8
  • 25
  • 1
    Try executing the User query by itself to make sure it's returning what you expect – Russell Oct 07 '15 at 18:42
  • 1
    What @Russell said. Also, double check that your keys match. They're case sensitive, so maybe you have a "User" key instead of "user", or "faceBookId" instead of "facebookId" Additionally, I know that the objective-c SDK has a specific query for users that you're supposed to use ( [PFUser query] ), so perhaps there is a similar thing for Swift. I bet that your userQuery isn't querying the User class the way you'd expect it to be. – Jake T. Oct 07 '15 at 19:44
  • 1
    Good catch @Jake T., The problem is definitely that that he is incorrectly querying for Users – Russell Oct 07 '15 at 20:03

1 Answers1

2

It looks like you aren't querying the User class properly. See This StackOverflow answer. You should be using the class "_User", or, more appropriately, var query : PFQuery = PFUser.query() instead of var query : PFQuery = PFQuery(className: "_User")

Community
  • 1
  • 1
Jake T.
  • 4,308
  • 2
  • 20
  • 48