I am trying to update an array column in a Parse class (i.e. column name is friendsRequestList) with an object. I searched and only could find one way to do so which is:
let query = PFQuery(className: "FriendsConnections")
query.getObjectInBackgroundWithId(self.friendObject.objectId!) {
(user: PFObject?, error: NSError?) -> Void in
if error != nil {
print(error)
} else if let user = user {
user.addObject(self.userObject, forKey: "friendsRequestList")
user.saveInBackground()
}
}
The only issue here is that function getObjectInBackgroundWithId requires object ID and I would like to have a query.wherekey instead as it works more with data I have in Parse.
How can I do the above without using objectID but using a whereKey instead.
Thanks
Update: New code based on answer provided but still didn't work:
let query = PFQuery(className: "FriendsConnections")
query.whereKey("appUsername", equalTo: self.friendObject.username!)
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// Do something with the found objects
if let objects = objects {
for object in objects {
print("Processing Object")
object.addObject(PFUser.currentUser()!["appUsername"], forKey: "friendsRequestList")
object.saveInBackground()
}
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}
friendObject?