ewindso / ios-parse-titanium-module

iOS Parse.com Titanium Module
Other
83 stars 23 forks source link

Further explanation of updateObject #11

Closed iantearle closed 11 years ago

iantearle commented 11 years ago

Could you please expand on the example of updateObject? Am I right in thinking that I have to edit the whole object and send it back to Parse? Rather than just sending the objectId to the class and passing any additional/updating existing data?

Perhaps an example showing the obj value before and after updating? How would you achieve updating the whole object in Titanium?

iantearle commented 11 years ago

Right, I have got so far with this, but am now stuck with PFObjects.

I am doing the following:

var userId = parse.currentUser;

jsonObj.amountDone = jsonObj.amountDone + 150; jsonObj.user = userId; parse.updateObject(jsonObj, function(data) { if(data.error) {

            } else {
                // worked!
            }
        });

The return I get from Parse is Error: invalid type for key user, expected *_User, but got string (Code: 111, Version: 1.1.26)

I get the same error if I do not pass in the user object separately too. There are a few things on the Parse help site relating to this error, but im not sure how I would resolve in this situation?

iantearle commented 11 years ago

I should also mention that the above error was from when I submitted just the User ObjectId, else I get this similar but object related error:

Error: invalid type for key user, expected *_User, but got string (Code: 111, Version: 1.1.26)

iantearle commented 11 years ago

Sorry to keep going on this, have whittled it down to it being a Pointer or a Relation - I cant seem to update if either of these objects are present.

One query, could the module not be how the JS/iOS sdk's from Parse operate currently, where by you set each object that has changed rather than sending back the whole object?

// Create the object. PFObject gameScore = [PFObject objectWithClassName:@"GameScore"]; [gameScore setObject:[NSNumber numberWithInt:1337] forKey:@"score"]; [gameScore setObject:@"Sean Plott" forKey:@"playerName"]; [gameScore setObject:[NSNumber numberWithBool:NO] forKey:@"cheatMode"]; [gameScore setObject:[NSArray arrayWithObjects:@"pwnage", @"flying", nil] forKey:@"skills"]; [gameScore saveInBackgroundWithBlock:^(BOOL succeeded, NSError error) {

// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the cloud. playerName hasn't changed.
[gameScore setObject:[NSNumber numberWithBool:YES] forKey:@"cheatMode"];
[gameScore setObject:[NSNumber numberWithInt:1338] forKey:@"score"];
[gameScore saveInBackground];

}];

ewindso commented 11 years ago

Are you using Titanium Alloy? I am posting a Gist of how I use their "Model" class to update the current user using updateObject. (Notice it's in the "save" where I call parse.updateObject).

https://gist.github.com/ewindso/ae0b433730b35642041c

iantearle commented 11 years ago

Yes I am. This looks great. Thanks!