Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to update object i already have in parse.com with javascript; what i did is i retirevied the object first with query but i dont know how to update it.

here is the code i use, whats wrong on it?

var GameScore = Parse.Object.extend("Driver");
var query = new Parse.Query(GameScore);
query.equalTo("DriverID", "9");
query.find({
  success: function(results) {

    alert("Successfully retrieved " + results.length + "DName");

     results.set("DName", "aaaa");
    results.save();
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});
share|improve this question
    
looks fine according to the documentation, what is the actual problem you are having? –  jbabey Nov 6 '12 at 13:24

2 Answers 2

up vote 11 down vote accepted

The difference between the question and your answer may not be obvious at first- So for everyone who has happened here- Use query.first instead of query.find.

query.find()  //don't use this if you are going to try and update an object

returns an array of objects, an array which has no method "set" or "save".

query.first() //use this instead

returns a single backbone style object which has those methods available.

share|improve this answer

I found the solution, incase someone needs it later

here it is:

var GameScore = Parse.Object.extend("Driver");
var query = new Parse.Query(GameScore);
query.equalTo("DriverID", "9");
query.first({
  success: function(object) {

     object.set("DName", "aaaa");
    object.save();


  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});
share|improve this answer
2  
The difference between the question and your answer may not be obvious at first- So for everyone who has happened here- Use query.first instead of query.find. Find returns an array of objects, and the array has no method "set" or "save". First returns a single backbone style object which has those methods available. –  Hairgami_Master May 22 '13 at 17:11
    
how can i do both save or update in one function. Set is for only update the rows. If row is not exist how to save inside the find function –  chan Aug 23 at 9:37
    
I'm able to retrive my values using objectId , but on success i try to set a new value , but always i get "{"code":101,"error":"object not found for update"}" error , please help me . Thanks In advance :) –  ManoharSingh 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.