0

I am unable to update row by object id in parse. I am using parse javascript sdk. Below is the code that i tried, but unable to update the column "read" to true. So my code pass in a threadId and user object to get all the comments of the user under the thread. What i want to do is to mark all the comments as read = true. I am not sure why this code is not working? any idea how i can update my rows?

readAllById: function(threadId , user){ 

            var ParseString = Parse.Object.extend("Comments");
            var query = new Parse.Query(ParseString);
            query.equalTo("threadId", threadId);
            query.equalTo("user" , user);
            query.ascending("createdAt");
            query.include("user");
            query.include("item");
            return query.find().then(function(response){

                 for(var i = 0; i < response.length; i++ ) {

                    console.log(response[i]);
                  var object_id = response[i].id;
                  query.set("id", object_id);
                  query.set("read", true);
                  query.save();
                }

            }, function(error){
                //something went wrong!
            });

        },
0

1 Answer 1

1

Okay. I got it working by using this code below

 readAllById: function(threadId , user){ 

            var ParseString = Parse.Object.extend("Comments");
            var query = new Parse.Query(ParseString);
            query.equalTo("threadId", threadId);
            query.equalTo("user" , user);
            query.ascending("createdAt");
            query.include("user");
            query.include("item");
            return query.find().then(function(response){

                 for(var i = 0; i < response.length; i++ ) {

                   var result = Parse.Object.extend("Comments");

                    var result = new Parse.Query(result);
                    query.get(response[i].id,{
                        success: function(result) {
                            result.set('read', true);
                            result.save();
                        }
                    });

                }

            }, function(error){
                //something went wrong!
            });

        },
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.