florian norbert bepunkt
florian norbert bepunkt

Reputation: 2539

parse cloud code beforeSave user object id

When a user signs up I need to add a row to another class (class B) with a reference pointer to this user and add a reference to the user class that points to the newly created row in class B.

Is there a way to get the Parse.User id in an beforeSave action?

If not what would be a way to achieve this with cloud code?

Upvotes: 0

Views: 584

Answers (1)

Alon
Alon

Reputation: 2929

beforesave the row didnt created yet, so you cant do pointer to something that still dont exist, and maybe error occur and the user never will create. In this case you have to use aftersave.

Do it with aftersave trigger

Parse.Cloud.afterSave(Parse.User, function(request) {
  var user = request.object;
  var ClassB = Parse.Object.extend("ClassB");
  var classb = new ClassB();
  classb.set("user", user);
  ....
  classb.save();
  ....
});

Upvotes: 2

Related Questions