Search code examples
swiftparse-platformrelational

Swift and Parse.com : relational query


On parse.com, I have a table named "ExerciseInstance" with a "pointer" to the "_User" table (with the user's objectId).

In my Swift code, I want to get all the rows from ExerciseInstance with UserAccount<_User> = "MZmMHtobwQ"

This does not work:

predicate = NSPredicate(format:"userAccount == %@", "MZmMHtobwQ")
var query = PFQuery(className:"ExerciseInstance", predicate:predicate)

Same problem with:

var query = PFQuery(className:"ExerciseInstance")
query.whereKey("userAccount", equalTo: "MZmMHtobwQ")

Any idea - what am I missing? Best, Tom


Solution

  • You cannot check to see if it is Equal to the objectId of the user, you must create the object first:

    var query = PFQuery(className:"ExerciseInstance")
    query.whereKey("userAccount", equalTo: PFObject(withoutDataWithClassName:"_User", objectId:"MZmMHtobwQ"))