Search code examples
javascriptparse-server

How to fetch a Parse object and include object references?


Can a Parse object be fetched with object.fetch and at the same time include its object references as in query.include?

Here is the query example:

let query = new Parse.Query("MyCollection");
query.include("MyObjectReference");
return query.find();

How to do it with a fetch command?


Solution

  • Parse JS SDK >= 2.0.2

    It is possible to fetch one or multiple objects with include:


    Parse JS SDK < 2.0.2

    It's not possible as the docs say:

    By default, when fetching an object, related Parse.Objects are not fetched. These objects’ values cannot be retrieved until they have been fetched like so:

    var post = fetchedComment.get("parent");
    post.fetch({
      success: function(post) {
        var title = post.get("title");
      }
    });