1

So I'm making a query to a table that I have for followers. Each result in the array has a userA and a userB object in it. When I try to access the userB object, it's null. However, when I access the elements of the array, userB shows...

Parse.Cloud.define("getFeed", function(request, response) {
  Parse.Cloud.useMasterKey();
  /***********************************
  **** GETTING FRIENDS LIST
  ***********************************/
  var query = new Parse.Query("Follow");
  var user = {"__type":"Pointer","className":"_User", 'objectId':request.params.user};
  query.equalTo("userA",user);
  query.include("userB");
  query.find({
    success: function(follows) {
      /***********************************
      **** GETTING FRIENDS' UPDATES
      ***********************************/
      //var feedUser = [];
      console.log("FOLLOWS: "+follows);
      console.log("FIRST FOLLOW *******"+follows[0]);
      console.log("USER B VALUE ********"+follows[0].userB);
      response.success(follows);
      // for(var i in follows) {
      //     feedUser.push(i.userB);
      // }


      // var queryUpdate = new Parse.Query("Goal");
      // queryUpdate.containedIn("user",feedUser);
      // queryUpdate.find({
      //   success: function(results) {
      //     response.success(friends);
      //   },
      //   error: function(error) {
      //     response.error(error);
      //   }
      // })
    },
    error: function(error) {
      response.error(error);
    }
  });

});

1 Answer 1

1

userB doesn't reside directly on it's parent object, so it's not accessible via

follows[0].userB

You'll need to properly traverse the object structure. When you include an object from another data class via a Pointer, the object will actually reside within the attributes property of it's parent object, so you'll need to access it like so:

follows[0].attributes.userB

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.