简体   繁体   English

在保存用户对象ID之前解析云代码

[英]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. 当用户注册时,我需要在指向该用户的引用指针的另一类(类B)中添加一行,并添加对该用户类的引用,该引用指向类B中新创建的行。

Is there a way to get the Parse.User id in an beforeSave action? 有没有一种方法可以在beforeSave操作中获取Parse.User ID?

If not what would be a way to achieve this with cloud code? 如果不是,用云代码实现此目标的方法是什么?

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();
  ....
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM