Reputation: 1932
Using parse.com and the JavaScipt SDK.
I've got a variable (friendName) that stores a _User record in it.
I know want to save this user back into parse under a new class and into a "pointer" column type. This is so the name can then be associated back to the _User class.
When I try and save the user using
requestFriend.set("username", friendName);
I get the following error in Chrome dev tools.
{"code":111,"error":"invalidtypeforkeyusername,expected*_User,butgotstring"}
To me this indicates that "friendName" is not in the correct format to save back to parse.
But have do I convert it into a _User object to that it can save successfully?
I can post up all code if it helps, but I thought I'd try and keep the post shorter to start with.
Screen shots attached.
Upvotes: 0
Views: 91
Reputation: 5215
Sounds like your schema is expecting it to be a User object. If friendName has the objectId of the user, you can create the object and the SDK will convert it to a pointer
new Parse.User({objectId: friendName});
If friendName is the username, you'd have to first query for the User and then set it. Something like this:
new Parse.Query("_User").equalTo("username", friendName).first().then(function(user) {
requestFriend.set("username", user);
return requestFriend.save();
});
Upvotes: 1