5

In an afterSave Cloud Code function as follows:

Parse.Cloud.afterSave("Post", function (request) {

    var post = request.object;

    if (post.has('author')) {
        var author = post.get('author');  
        // author is a Link to a specific Parse.User   
    }

}

I am trying to get the email of the Parse user pointed to by the Post's author field.

In the above example, author ends up containing the following:

{
    "__type":"Pointer",
    "className":"_User",
    "objectId":"413wgL9vf1"
}

Essentially, I want to read the email property of the user pointed to by the pointer.

I tried doing author.get('email') and that failed, saying "undefined". The email is set in the database.

What's the right way to do this? Should I be writing a query against the User class using the objectId from the link, or is there an easier way?

Gabriel Bauman
  • 2,270
  • 1
  • 22
  • 36

1 Answers1

0

Turns out all I needed to do was author.fetch().then(...).

Gabriel Bauman
  • 2,270
  • 1
  • 22
  • 36