0

Here is the use case:

A is model, and B is a model related to A.

On A's afterSave(), I send out a push notification. On B's afterSave(), I send out a push notification. But on B's afterSave(), I call save() on A, and this results in A's afterSave triggering another push notification. I'd like to avoid this.

How can I save A in B's afterSave() such that A's afterSave() isn't called?

What would be even better is being able to somehow pass the message along to A that its B thats causing the afterSave() i.e. in general, a cloud function and not a direct http request thats causing the afterSave(), and then conditionally perform the remaining logic.

Help is much appreciated! Thanks!

John Doe
  • 1,005
  • 2
  • 8
  • 23
  • Maybe have a flag in A that is set in B afterSave() before calling save on A? If SavedByB is set to true, then A's afterSave() does not call the push notification (afterSave() is still run, but the push is conditional), and of course resets the SavedByB flag to false. – Marius Waldal Aug 14 '14 at 07:10
  • 2
    If you save A with `useMasterKey` then the `master` property in the `afterSave` request will be `true`. You might be able to use this as an indicator without adding extra fields etc. – Chris Sainty Aug 14 '14 at 07:25
  • @Handsomeguy Is there a way to scope this flag to the request? There might be concurrent requests being served by A and B, and I'd ideally like the flag to be acknowledged on a per request basis. – John Doe Aug 14 '14 at 19:16
  • @ChrisSainty Hmm..wasn't aware of that. I'll need to think about it. But, is there a way to add arbitrary properties to the request object that is passed along to A from B? – John Doe Aug 14 '14 at 19:18
  • @JohnDoe Not that I know of, but it is a good idea and worth suggesting to the dev team. – Chris Sainty Aug 15 '14 at 06:51
  • I have not encountered such a feature, but I can't answer for sure. But I wouldn't think so. – Marius Waldal Aug 15 '14 at 11:49
  • @ChrisSainty Because, you mentioned the master property, I got thinking and came up with http://stackoverflow.com/questions/25330855/parse-com-is-there-a-way-to-perform-a-job-as-a-particular-user. Do you think you could help me out with it? Thanks! – John Doe Aug 15 '14 at 17:07
  • @JohnDoe that link is broken, can you tell post the solution again? – Mars Oct 17 '15 at 12:25

0 Answers0