0

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.

enter image description here

1 Answer 1

1

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();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.