title: Parse - Check for Update inside BeforeSave in Cloud Code
body: <p>I want to check that I am not saving a duplicate entry for the attend status of an event - so on BeforeSave I am checking that the event rsvp has not already been entered - if it has, I want to know if it needs to be updated. If it does, I want to do an update instead of create a new RSVP entry.</p>
  
  <p>This is my code - I can't seem to get it to work, even with the simplist update inside BeforeSave.</p>
  
  <pre><code>Parse.Cloud.beforeSave("Rsvps", function(request, response) {
  
  var eventid = request.object.get("eventid");
  var userid = request.object.get("userid");
  var rsvp_status = request.object.get("rsvp_status");
  
  var Rsvps = Parse.Object.extend("Rsvps");
  var query = new Parse.Query(Rsvps);
  query.equalTo("eventid", eventid);
  query.equalTo("userid", userid);
  query.first({
    success: function(object) {
      if (object) {
          // response.error("An RSVP for this event already exists.");
          request.object.id = object.id;
          request.object.set('rsvp_status', "attending");
          request.object.save();
      } else {
        response.success();
      }
    },
    error: function(error) {
      response.error("Error: " + error.code + " " + error.message);
    }
  });
  
  });
  </code></pre>
  
  <p>I've tried so many variation of this without any joy - this my latest attempt.</p>