0

I am having trouble getting data from the nested pointers in my array of pointers from a query. I have an array of pointers like so: [{"__type":"Pointer","className":"QuizData","objectId":"rmwJrV55c7"},{"__type":"Pointer","className":"QuizData","objectId":"2132q8i9np”}, etc…]

That QuizData class also has a column named “ad” which is a Pointer to the “Ads” class. I can get the QuizData in a query using the following include statements on my query like so:

var __quizAdQueueQuery = new Parse.Query(QuizAdQueue);
__quizAdQueueQuery.equalTo("user", __request.user);
__quizAdQueueQuery.include("quizAdArr”);
__quizAdQueueQuery.include(["quizAdArr.QuizData"]);

BUT Neither of these or both combined don’t work as when I try to get column data from the ad it’s always undefined:

__quizAdQueueQuery.include(["quizAdArr.QuizData.ad"]);
__quizAdQueueQuery.include(["quizAdArr.QuizData.Ads"]);

This is my return from that query, where the column data "mediaType" that I am trying to access is always undefined:

return __quizAdQueueQuery.first().then(function(__resultsObj)
{

  __quizQueueObj = __resultsObj;
  __userQuizQueueArr = __quizQueueObj.get("quizAdArr");

  var __quiz;
  var __ad;
  var __seenAd;
  var __lengthInt = __userQuizQueueArr.length;
  var __mediaTypeStr = __request.params.mediaType;
  var __matchedQuizzesArr = [];

  for (var __i = 1; __i < __lengthInt; __i++)
  {
    __quiz = __userQuizQueueArr[__i];
    // console.log('__quiz.get("name") = '+__quiz.get("name"));
    __ad = __quiz.get("ad");
    // console.log("__ad.id = "+__ad.id);
    //THE MEDIA TYPE IS ALWAYS RETURNING UNDEFINED HERE!!!
    console.log('__ad.get("mediaType") = '+__ad.get("mediaType")+', __mediaTypeStr = '+__mediaTypeStr);

    if (__ad.get("mediaType") == __mediaTypeStr)
    {
      //put all matches in array to be sorted
      __matchedQuizzesArr.push(__userQuizQueueArr[__i]);
      console.log("__matchedQuizzesArr.length = "+__matchedQuizzesArr.length);
    }
  }

  return __matchedQuizzesArr;
});

Thanks for any help you can give! I also posted this as a bug in the Parse/Facebook issue reporter but was redirected here, so if this is a bug I can reopen it: https://developers.facebook.com/bugs/923988310993165/

EDIT Here is the updated, working query with nested includes for clarity:

var __quizAdQueueQuery = new Parse.Query(QuizAdQueue);
__quizAdQueueQuery.equalTo("user", __request.user);
__quizAdQueueQuery.include('quizAdArr');
__quizAdQueueQuery.include('quizAdArr.ad');

1 Answer 1

1

This should work (you only need to list the column names):

query.include('quizAdArr.ad');

Here's why:

  • You're querying QuizAdQueue so you don't need to list that
  • The QuizAdQueue class has an array in quizAdArr so you include it: query.include('quizAdArr');
  • Each quizAdArr element is a QuizData with an ad so you include it: query.include('quizAdArr.ad');

The issue was that you were including QuizData which is the name of a class and not a column name

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

1 Comment

Thanks David! That did it. I would recommend the Parse.com team enhance their two lines of documentation on this because their example is not clear plus they use brackets. A clear visualization of classes and the nested classes with class names and column names would help as well. Here is the documentation: "You can also do multi level includes using dot notation. If you wanted to include the post for a comment and the post's author as well you can do:" query.include(["post.author"]);

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.