title: Parse.com Cloud Code - Creating new Instance of another object on before save
body: <p>I have two classes, Groups and memberships. When a group is made, I'd like its corresponding membership to be made as well. I attempt to do so like this:</p>
  
  <pre><code>Parse.Cloud.beforeSave("Group", function(request, response) {   
      var name = request.object.get("name");
  
      if (!name) {
          response.error("A Group must have a name");
      } else {
          if (!(/^\w+$/i.test(name))){
              response.error("Only letters and numbers, please.");
          }
          var query = new Parse.Query("Group");
          query.equalTo("name", name);
          query.first({
              success: function(object) {
                  if (object) {
                      response.error("A group with this name exists.");
                  } else {
                      createMembershipForGroup(request.object, Parse.User);
                      response.success();
                  }
              },
              error: function(error) {
                  response.error("Could not validate Uniqueness");
              }
          });
      }
  });
  
  createMembershipForGroup = function(group, user) {
      var MembershipClass = Parse.Object.extend("Membership");
      var membership = new MembershipClass();
  
      membership.set("group", group);
      membership.set("user", user);
      membership.save(null,{
        success:function(membership) { 
          response.success(membership);
        },
        error:function(error) {
          response.error(error);
        }
      });
  }
  </code></pre>
  
  <p>I receive an error back, saying the following:</p>
  
  <blockquote>
    <p>E2014-05-06T21:40:10.740Z] v30: before_save triggered for Group for
    user xgzDnZ9h0A   Input:
    {"original":null,"update":{"admin":{"objectId":"xgzDnZ9h0A","className":"_User","__type":"Pointer"},"name":"test","public":false}}
    Result: undefined</p>
  </blockquote>
  
  <p>Not too sure what the error is. How could I go about debugging code like this so I can isolate the issue easily? </p>