PFUser 上的 AfterSave 检查是否在创建或更新
AfterSave on PFUser checking if on creation or update
我很难区分 PFUser 是正在更新还是第一次保存。我实施了在 parse.com here 上找到的解决方案。但是,它并没有像 link 中的答案中所解释的那样工作。无论是在创建还是更新时,我总是得到一个错误。这是我实现的代码。
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.useMasterKey();
//this error log prints false regardless of if the user is signing up.
// or having a key updated.
console.error(request.object.existed());
if (!request.object.existed()) {
//This is on sign up, the user has not existed prior.
//This doesn't work. This block of code is always run.
}
else {
//This is supposedly when the user is having a key updated.
//Unfortunately, this code is never run regardless.
}
)}
这段代码的行为与我预期的不一样,因为 request.object.existed()
总是 returns 错误。我认为这可能必须这样做,因为这是在保存 PFUser
而不是一些通用的 PFObject
。在 PFUser afterSave 上使用 request.object.existed()
时我遗漏了什么吗?谢谢。
这似乎是一个未解决的 Parse 云 bug
可能的解决方法是检查创建时间和更新时间之间的差异,以查看您的对象是正在更新还是正在创建。
我很难区分 PFUser 是正在更新还是第一次保存。我实施了在 parse.com here 上找到的解决方案。但是,它并没有像 link 中的答案中所解释的那样工作。无论是在创建还是更新时,我总是得到一个错误。这是我实现的代码。
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.useMasterKey();
//this error log prints false regardless of if the user is signing up.
// or having a key updated.
console.error(request.object.existed());
if (!request.object.existed()) {
//This is on sign up, the user has not existed prior.
//This doesn't work. This block of code is always run.
}
else {
//This is supposedly when the user is having a key updated.
//Unfortunately, this code is never run regardless.
}
)}
这段代码的行为与我预期的不一样,因为 request.object.existed()
总是 returns 错误。我认为这可能必须这样做,因为这是在保存 PFUser
而不是一些通用的 PFObject
。在 PFUser afterSave 上使用 request.object.existed()
时我遗漏了什么吗?谢谢。
这似乎是一个未解决的 Parse 云 bug
可能的解决方法是检查创建时间和更新时间之间的差异,以查看您的对象是正在更新还是正在创建。