title: Query Parent and child data in one call - parse.com + javascript
body: <p>I am trying to understand how to query related classes in one call from parse.com using javascript.</p>
  
  <p>I have 2 classes Post and Comment.  Post has a column of type relation named 'Comment' and Comment has a column 'parent' of type pointer.</p>
  
  <p>I use the following following code based on parse docs, to save a post and related comment</p>
  
  <pre><code>var Post = Parse.Object.extend("Post");
  var Comment = Parse.Object.extend("Comment");
  
  //Create the post
  var myPost = new Post();
  myPost.set("title", "I'm Hungry");
  myPost.set("content", "Where should we go for lunch?");
  
  // Create the comment
  var myComment = new Comment();
  myComment.set("text", "Let's do subway.");
  
  myComment.set("parent", myPost);     
  myComment.save();
  </code></pre>
  
  <p>I am trying to query data like this</p>
  
  <pre><code>var query = new Parse.Query("Post");
  query.descending("createdAt");
  
  query.find({
      success: function(results) {
        for(var i = 0; i &lt; results.length; i++) {
          var post = results[i];
          var relation = post.relation('Comment');
  
          relation.query().find({
            success: function(comments) {
              for(var j = 0; j &lt; comments.length; j++) {
                console.log(comments[j].get("content"));
              }
            }
          });
        }
      },
      error: function(error) {
        alert("Error: " + error.code + " " + error.message);
      }
    }); 
  </code></pre>
  
  <p>Can anybody tell me what i am doing wrong here?</p>