Tom - Lunabee.com
Tom - Lunabee.com

Reputation: 356

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

Upvotes: 4

Views: 2390

Answers (2)

Nicko Prasetio
Nicko Prasetio

Reputation: 1

Try this:

var teamQuery = PFQuery(className:"Team")
teamQuery.whereKey("winPct", greaterThan:0.5)
var userQuery = PFUser.query()
userQuery!.whereKey("hometown", matchesKey:"city", inQuery:teamQuery)
userQuery!.findObjectsInBackgroundWithBlock {
(results: [PFObject]?, error: NSError?) -> Void in
     if error == nil {
     // results will contain users with a hometown team with a winning record
   }
}

Upvotes: 0

Jacob
Jacob

Reputation: 2338

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"))

Upvotes: 4

Related Questions