Reputation: 13527
Is it possible to update object's value without having to fetch the object first? I could save a bunch of Parse requests if this would work.
this is what I have now:
// this uses two Parse requests
PFQuery *q = [PFQuery queryWithClassName:@"conversations"];
// 1st request
[q getObjectInBackgroundWithId:_conversationID block:^(PFObject *object, NSError *error){
[object setValue:message forKey:@"lastMessage"];
[object saveInBackground]; // 2nd request
}];
I want to do something like this:
// this would use one Parse request if it would work
PFQuery *q = [PFQuery queryWithClassName:@"conversations"];
[q whereKey:@"objectId" equalTo:_conversationID]
[q setValue:message forKey:@"lastMessage"];
[q executeInBackground]; // the only request
I know executeInBackground doesn't exist but hopefully there is something else that I'm missing :)
Upvotes: 0
Views: 389
Reputation: 9942
No, that is not possible. Depending on your use case, you might be able to use cloud code.
Based on your code I'm guessing you want to add a chat message to a conversation. Instead of getting the conversation object and adding a message to it, and then save it, you could do this instead:
All chat messages get their own object. This means that when a user writes a message, this is one request: a new ChatMessage object including a property that is the conversation object. In the afterSave hook (cloud code), you could have a small script that gets the conversation object and adds a pointer to a pointer array in the conversation.
This lets you track all messages in a conversation, without doing all the queries on the device.
Upvotes: 1