Parse aftersave cloud function returns a success result but doesn't execute success function

痞子三分冷 提交于 2019-12-11 19:46:18

问题


I'm having trouble getting my aftersave cloud function to increment a value in another data table. The Parse documentation is a bit confusing on this front.

I have a table called "CandidateVotes" that stores a row for each vote on a "candidate" - and when a new vote row is saved, I would like to increment the total votes count stored in a different table called "CategoryCandidates" which has a row for each "candidate".

So the relevant information:
- Votes table is called "CandidateVotes"
- Candidates table is called "CategoryCandidates"
- Total votes count column in CategoryCandidates table is called "votes"
- I'm initializing the "CategoryCandidates" row with a "votes" value of 0

Here's my Parse aftersave cloud function:

Parse.Cloud.afterSave("CandidateVotes", function(request) {
  query = new Parse.Query("CategoryCandidates");
  query.get(request.object.get("candidateID").objectID, {
    success: function(candidate) {
      candidate.increment("votes");
      candidate.save();
    },
    error: function(error) {
    }
  });
});

This is what I see in the cloud code log:

I2015-09-05T04:18:21.151Z]v15 after_save triggered for CandidateVotes for user 7YfU2ETvb3:
  Input: {"object":{"candidateID":{"__type":"Pointer","className":"CategoryCandidates","objectId":"XcfYPgijtn"},"createdAt":"2015-09-05T04:18:21.150Z","objectId":"sLySF6MvvQ","updatedAt":"2015-09-05T04:18:21.150Z","userID":{"__type":"Pointer","className":"_User","objectId":"7YfU2ETvb3"}}}
  Result: Success

BUT the "votes" column is not incrementing. It remains 0.

Any ideas would be very much appreciated!


回答1:


The objectId property is just id in JavaScript.

//replace
request.object.get("candidateID").objectID
//with this
request.object.get("candidateID").id


来源:https://stackoverflow.com/questions/32409920/parse-aftersave-cloud-function-returns-a-success-result-but-doesnt-execute-succ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!