1

I have a function that creates a new Comment object and saves it to the database. Before saving it the comment text, the id of the object it is attached to, as well as a pointer to the user object that posted the comment are set on the object before it is saved. However when run I get the error:

Cannot create pointer to unsaved parse object

Here is the code in question:

this.postComment = function(comment, objectId) {
   // Get logged in user
   var currentUser = Parse.User.current();

   // extend and create new Comment object
   var Comment = Parse.Object.extend('Comment');
   var comment = new Comment();
   // Set fields to be saved
   comment.set('object', objectId);
   comment.set('commentText', comment);
   comment.set('user', currentUser);

   // Save new comment to db
   comment.save(null, {
      success: function(comment) {
         console.log("success");
      },
      error: function(comment, error) {
         console.log(error);
      }
   });
}    

This leads me to believe that there is something wrong with the User object that I am pointing to but the User exists in the database and is even retrieved using Parse.User.current()

I've looked at other posts with the same error but I have yet to find a solution to this problem. Please let me know if there is any more information I can provide.

5
  • what line are you getting that error? Check on console Commented Feb 4, 2016 at 21:16
  • @pratikwebdev The error comes from the comment.save line. I can see an console logs before that line but do not see the success or error function logs. Commented Feb 5, 2016 at 16:46
  • could you change the function parameter? Local comment to function and parameter passed to function are named same and assignment is done with set. Check what value is coming in debugger for comment object inside function during set statements. Change the parameter first for function definition and try. Commented Feb 5, 2016 at 19:14
  • That was it, I can't believe I didn't see it. Thank you so much for your help. Commented Feb 5, 2016 at 19:25
  • Thats great. Code on! Commented Feb 5, 2016 at 19:35

1 Answer 1

1

Just change the function parameter name or handle local comment object assignment. Check if it works after.

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.